資源簡介
我寫的一些關于平滑去噪、銳化、灰度、偽彩色操作的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?????????????for?(int?i?=?0;?i?????????????for?(int?i?=?0;?i?????????????for?(int?i?=?0;?i?
????????????//卷積運算數組橫向掃描
????????????for?(int?line?=?1;?line?????????????{
????????????????for?(int?col?=?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
評論
共有 條評論