Gray() public static méthode

图片灰度化处理指针法
public static Gray ( Bitmap img, int type = 2 ) : Image
img System.Drawing.Bitmap 待处理图片
type int 1:最大值;2:平均值;3:加权平均;默认平均值
Résultat Image
Exemple #1
0
        /// <summary>
        /// 三种方式下灰度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_gray_Click(object sender, EventArgs e)
        {
            Image img      = pborigin.Image;
            Image img_grey = (Image)img.Clone();

            imgOriginal = Image2Num((Bitmap )img_grey);
            if (!Directory.Exists("experiment\\"))
            {
                Directory.CreateDirectory("experiment\\");
            }
            //imgurl = pborigin.ImageLocation;
            WriteToFile(imgOriginal, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_original.txt");
            //WriteToFile(imgGraying, "e:\\yanzhengma\\gray"+pborigin.ImageLocation);
            //灰度化处理
            //img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.AverageValue);//平均
            //img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.MaxValue );//最大值
            // img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.WeightAverage);//加权
            graytype = 2;
            if (rb_max.Checked)
            {
                graytype = 1;
            }
            if (rb_quanzhong.Checked)
            {
                graytype = 3;
            }
            img_grey  = ImageProcess.Gray((Bitmap)img_grey, graytype);
            imgGreied = Image2Num((Bitmap)img_grey);
            WriteToFile(imgGreied, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_greied.txt");
            pb_grey.Image = img_grey;
        }