• 大小: 28KB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2021-05-06
  • 语言: C#
  • 标签: 图像处理  

资源简介

我写的一些关于平滑去噪、锐化、灰度、伪彩色操作的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


评论

共有 条评论