资源简介
我写的一些关于平滑去噪、锐化、灰度、伪彩色操作的C#代码。大家可以参考一下
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Sharp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“@copyright 任梦菲 2008302580108“);
Bitmap oldPicture = new Bitmap(@“D:\oldPicture.jpg“); //未处理的图片所在路径
Console.WriteLine(“开始处理照片...“);
//平滑处理
int[] smoothT = { 1 2 1 2 4 2 1 2 1 }; int smoothC = 16; //高斯模板
Bitmap smoothPicture = Program.SmoothSharp(oldPicturesmoothTsmoothC );
Console.WriteLine(“平滑去噪完毕!开始锐化处理...“);
//锐化处理
int[] sharpT = { -1 -1 -1 -1 9 -1 -1 -1 -1 }; //拉普拉斯高增滤波模板
Bitmap sharpPicture = Program.SmoothSharp(smoothPicture sharpT 1);
Console.WriteLine(“锐化完毕!开始灰度变换处理...“);
//灰度变换
Bitmap greyPicture = Program.Contrast(sharpPicture);
Console.WriteLine(“灰度变换完毕!开始伪彩色处理...“);
greyPicture.Save(@“D:\grey.jpg“);
//伪彩色处理
int colorLevel = 16;
Bitmap colorPicture = Program.Colorful(sharpPicture colorLevel);
colorPicture.Save(@“D:\newPicture.jpg“);
Console.WriteLine(“全部处理完毕!“);
}
#region 平滑和锐化处理
///
///静态方法,平滑锐化处理
///
/// 需要修改的图像
/// 修改后的图像
static Bitmap SmoothSharp(Bitmap oldPicture int[] smoothT int smoothC)
{
int width = oldPicture.Width; //图片的宽度,以像素为单位
int height = oldPicture.Height; //图片的高度,以像素为单位
Bitmap newPicture = new Bitmap(width height); //处理后的新图
int[] template = smoothT; //将3*3的卷积模板存入一维数组中
int count = smoothC; //模板数组要除的整数
Color pixel;
//图像边缘不作处理
for (int i = 0; i < width; i++) newPicture.SetPixel(i 0 oldPicture.GetPixel(i 0));
for (int i = 0; i < width; i++) newPicture.SetPixel(i height - 1 oldPicture.GetPixel(i height - 1));
for (int i = 0; i < height; i++) newPicture.SetPixel(0 i oldPicture.GetPixel(0 i));
for (int i = 0; i < height; i++) newPicture.SetPixel(width - 1 i oldPicture.GetPixel(width - 1 i));
//卷积运算数组横向扫描
for (int line = 1; line < height - 1; line++)
{
for (int col = 1; col < width - 1; col++)
{
int r = 0 g = 0 b = 0 index = 0;
//3*3模板,加权求和
for (int l = -1; l < 2; l++)
{
for (int c = -1; c < 2; c++)
{
pixel = oldPicture.GetPixel(col + c line + l);
r += pixel.R * template[inde
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7680 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\bin\Debug\Sharp.exe
文件 17920 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\bin\Debug\Sharp.pdb
文件 14328 2010-10-21 23:18 图像处理第二次作业,各种处理方法的综合\Sharp\bin\Debug\Sharp.vshost.exe
文件 490 2009-06-11 05:14 图像处理第二次作业,各种处理方法的综合\Sharp\bin\Debug\Sharp.vshost.exe.manifest
文件 316 2010-10-21 23:18 图像处理第二次作业,各种处理方法的综合\Sharp\obj\Debug\Sharp.csproj.FileListAbsolute.txt
文件 7680 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\obj\Debug\Sharp.exe
文件 17920 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\obj\Debug\Sharp.pdb
文件 8846 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\Program.cs
文件 1342 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合\Sharp\Properties\AssemblyInfo.cs
文件 2527 2010-10-20 00:17 图像处理第二次作业,各种处理方法的综合\Sharp\Sharp.csproj
文件 905 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合\Sharp.sln
..A..H. 11264 2010-10-22 00:52 图像处理第二次作业,各种处理方法的综合\Sharp.suo
目录 0 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合\Sharp\obj\Debug\TempPE
目录 0 2010-10-21 02:00 图像处理第二次作业,各种处理方法的综合\Sharp\bin\Debug
目录 0 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp\obj\Debug
目录 0 2010-10-20 00:03 图像处理第二次作业,各种处理方法的综合\Sharp\bin
目录 0 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合\Sharp\obj
目录 0 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合\Sharp\Properties
目录 0 2010-10-21 16:47 图像处理第二次作业,各种处理方法的综合\Sharp
目录 0 2010-10-17 20:16 图像处理第二次作业,各种处理方法的综合
----------- --------- ---------- ----- ----
91218 20
相关资源
- DCM文件转图像,并高清处理图像
- c#车牌识别系统附30张测试图片
- c#编写小envi,包括均值方差相关系数
- C#图像处理使用EMGUCV
- C#数字图像处理算法典型
- c#图像处理傅立叶变换 几何运算 直方
- c#数字图像处理(平滑、修正、锐化、
- 图像处理软件源码C#
- 数字图像处理设计软件C#版
- AForge.net
- C#数字图像处理算法典型赵春江随书源
- C# 图像处理
- C#编写数字图像处理程序
- C#数字图像处理 关于遥感图像处理的
- C#图像处理编程+源程序
- c#数字图像处理之几何运算
- c#数字图像处理之点运算及直方图
- c#图像处理源代码包含边缘检测,灰度
- C#图像处理源程序
- C# 图像处理 源代码 均值滤波 中值滤
- C#图像处理六项图片处理功能及截图工
- 基于矩阵的图像处理绘图软件源码
- 遥感图像处理课程设计代码
- C#数字图像处理算法典型随书光盘源码
- C# 数字图像处理技术光盘源码
- C#数字图像处理算法典型包含源码
- C#数字图像处理算法典型](随书光盘
- C# 图像处理、神经网络、遗传算法集
- C# 图像处理软件及其源码
- c#图像噪声平滑处理
评论
共有 条评论