• 大小: 1.41MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2022-06-03
  • 语言: C#
  • 标签: 灰度化  

资源简介

自己实现的小栗子 适合新人了解c#实现对图片灰度化、二值化的过程

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DealPicture
{
    class Deal
    {
        static Bitmap bm;
        static Color blackColor = Color.FromArgb(0 0 0);
        static Color whiteColor = Color.FromArgb(255 255 255);
        static Color blueColor = Color.FromArgb(0 255 0);
        //static Dictionary dic = new Dictionary();
        static List xlist = new List();
        static List yList = new List();

        //移除的方法
        public static Bitmap RemoveRed(Bitmap bmp)
        {
            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    Color color = bmp.GetPixel(i j);

                    if (color.R - color.B > 10)
                    {
                        //dic[i] = j;
                        xlist.Add(i);
                        yList.Add(j);
                        bmp.SetPixel(i j whiteColor);
                    }
                }
                //ToGrey(bm);
            }
            return bmp;
        }
        //灰度化
        public static Bitmap ToGrey(Bitmap img1)
        {
            for (int i = 0; i < img1.Width; i++)
            {
                for (int j = 0; j < img1.Height; j++)
                {
                    Color pixelColor = img1.GetPixel(i j);
                    //计算灰度值          
                    int grey = (int)(0.299 * pixelColor.R + 0.587 * pixelColor.G + 0.114 * pixelColor.B);
                    Color newColor = Color.FromArgb(grey grey grey);
                    img1.SetPixel(i j newColor);
                }
            }
            return img1;
        }
        //二值化方法
        public static Bitmap ConvertToDouble(Bitmap bmpint value)
        {
            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    Color color = bmp.GetPixel(i j);
                    if (color.R < value)
                    {
                        bmp.SetPixel(i j blackColor);
                    }
                    else
                    {
                        bmp.SetPixel(i j whiteColor);
                    }
                }
            }
            return bmp;
        }
        //盖蓝章的方法
        public static Bitmap DoBlue(Bitmap bmp)
        {
            for (int i = 0; i < xlist.Count; i++)
            {
                bmp.SetPixel(xlist[i] yList[i] blueColor);
            }
            return bmp;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-28 18:23  DealPicture\
     目录           0  2017-09-28 18:25  DealPicture\DealPicture\
     文件         187  2017-09-28 14:31  DealPicture\DealPicture\App.config
     文件        2797  2017-09-28 17:24  DealPicture\DealPicture\Deal.cs
     文件        3921  2017-09-28 18:14  DealPicture\DealPicture\DealPicture.csproj
     文件         228  2017-09-28 18:16  DealPicture\DealPicture\DealPicture.csproj.user
     文件        7505  2017-09-28 18:15  DealPicture\DealPicture\MainFrm.Designer.cs
     文件        3192  2017-09-28 18:25  DealPicture\DealPicture\MainFrm.cs
     文件        5817  2017-09-28 18:15  DealPicture\DealPicture\MainFrm.resx
     文件         525  2017-09-28 17:14  DealPicture\DealPicture\Program.cs
     目录           0  2017-09-28 18:20  DealPicture\DealPicture\Properties\
     文件        1364  2017-09-28 14:31  DealPicture\DealPicture\Properties\AssemblyInfo.cs
     文件        2874  2017-09-28 14:31  DealPicture\DealPicture\Properties\Resources.Designer.cs
     文件        5612  2017-09-28 14:31  DealPicture\DealPicture\Properties\Resources.resx
     文件        1098  2017-09-28 14:31  DealPicture\DealPicture\Properties\Settings.Designer.cs
     文件         249  2017-09-28 14:31  DealPicture\DealPicture\Properties\Settings.settings
     目录           0  2017-09-28 18:20  DealPicture\DealPicture\bin\
     目录           0  2017-09-28 18:21  DealPicture\DealPicture\bin\Debug\
     文件    11605886  2017-09-28 18:13  DealPicture\DealPicture\bin\Debug\9.bmp
     文件       12800  2017-09-28 18:16  DealPicture\DealPicture\bin\Debug\DealPicture.exe
     文件         187  2017-09-28 14:31  DealPicture\DealPicture\bin\Debug\DealPicture.exe.config
     文件       34304  2017-09-28 18:16  DealPicture\DealPicture\bin\Debug\DealPicture.pdb
     文件       24224  2017-09-28 18:23  DealPicture\DealPicture\bin\Debug\DealPicture.vshost.exe
     文件         187  2017-09-28 14:31  DealPicture\DealPicture\bin\Debug\DealPicture.vshost.exe.config
     文件         490  2013-03-18 17:00  DealPicture\DealPicture\bin\Debug\DealPicture.vshost.exe.manifest
     文件        1002  2017-09-28 17:25  DealPicture\test0927.sln
     目录           0  2017-09-28 18:19  DealPicture\DealPicture\obj\
     目录           0  2017-09-28 18:20  DealPicture\DealPicture\obj\Debug\
     文件         180  2017-09-28 18:16  DealPicture\DealPicture\obj\Debug\DealPicture.MainFrm.resources
     文件         180  2017-09-28 18:16  DealPicture\DealPicture\obj\Debug\DealPicture.Properties.Resources.resources
     文件         858  2017-09-28 18:23  DealPicture\DealPicture\obj\Debug\DealPicture.csproj.FileListAbsolute.txt
............此处省略13个文件信息

评论

共有 条评论