• 大小: 262KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: C#  图像处理  二值化  

资源简介

C#实现的二值化处理, 比较简单, 仅供参考.

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Pic2Val
{
    public partial class Form1 : Form
    {
        OpenFileDialog choosepic = new OpenFileDialog();
        FolderBrowserDialog savepic = new FolderBrowserDialog();
        int filenumcolorthreshold; 


        public Form1()
        {
            InitializeComponent();
            choosepic.Multiselect = true;
            
        }

        private void button1_Click(object sender EventArgs e)
        {
            if (choosepic.ShowDialog() == DialogResult.OK)
            {
                filenum=choosepic.FileNames.GetLength(0);
                lb_filenum.Text = “The number of files you have choosen: “ + filenum.ToString()+“.“;
            }
            if (savepic.ShowDialog() == DialogResult.OK)
            {
                lb_savepath.Text = savepic.SelectedPath;
            }
        }

        private void button2_Click(object sender EventArgs e)
        {
            int i j k;
            Bitmap picbuf;

            progressBar1.Value = 0;
            progressBar1.Refresh();
            
            colorthreshold = trackBar1.Value;
            for (i = 0; i < filenum; i++)
            {
                picbuf = new Bitmap(choosepic.FileNames[i]);
                for (j = 1; j < picbuf.Width; j++)
                {
                    for (k = 1; k < picbuf.Height; k++)
                    {
                        if ((picbuf.GetPixel(j k).R + picbuf.GetPixel(j k).B + picbuf.GetPixel(j k).G)/3 < colorthreshold)
                        {
                                picbuf.SetPixel(jkColor.Black);
                        }
                        else if ((picbuf.GetPixel(j k).R + picbuf.GetPixel(j k).B + picbuf.GetPixel(j k).G)/3 > colorthreshold)
                        {
                            picbuf.SetPixel(j k Color.White);
                        }
                    }
                    progressBar2.Value = (j+1) * 100 / picbuf.Width;
                    progressBar2.Refresh();
                }
                progressBar1.Value = (i + 1) * 100 / filenum;
                progressBar1.Refresh();
                picbuf.Save(lb_savepath.Text.Replace(“\\“ “\\\\“) + “\\picture_“ + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + “_“ + i.ToString() + “.jpg“);
                //picbuf.Save( choosepic.FileNames[i].Insert(choosepic.FileNames[i].Length-4“_converted“).Replace(“\\“ “\\\\“));
            }
            lb_filenum.Text.Insert(lb_filenum.Text.Length - 1 “ 完成!“);
        }

        private void trackBar1_Scroll(object sender EventArgs e)
        {
            lb_thdval.Text = trackBar1.Value.ToString();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-03-05 11:10  Pic2val\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\
     文件         911  2013-12-17 18:05  Pic2val\Pic2Val\Pic2Val.sln
     文件       31744  2013-12-18 17:19  Pic2val\Pic2Val\Pic2Val.v11.suo
     文件         187  2013-12-17 18:05  Pic2val\Pic2Val\Pic2Val\App.config
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\bin\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\bin\Debug\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Application Files\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Application Files\Pic2Val_1_0_0_0\
     文件         187  2013-12-17 18:05  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Application Files\Pic2Val_1_0_0_0\Pic2Val.exe.config.deploy
     文件       10752  2013-12-17 18:56  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Application Files\Pic2Val_1_0_0_0\Pic2Val.exe.deploy
     文件        7144  2013-12-17 18:56  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Application Files\Pic2Val_1_0_0_0\Pic2Val.exe.manifest
     文件        5619  2013-12-17 18:56  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\Pic2Val.application
     文件      432072  2013-12-17 18:56  Pic2val\Pic2Val\Pic2Val\bin\Debug\app.publish\setup.exe
     文件        1822  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.application
     文件       11264  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.exe
     文件         187  2013-12-17 18:05  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.exe.config
     文件        3417  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.exe.manifest
     文件       26112  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.pdb
     文件        1822  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.vshost.application
     文件       22984  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.vshost.exe
     文件         187  2013-12-17 18:05  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.vshost.exe.config
     文件        3417  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\bin\Debug\Pic2Val.vshost.exe.manifest
     文件        2993  2013-12-18 17:18  Pic2val\Pic2Val\Pic2Val\Form1.cs
     文件        7219  2013-12-18 17:14  Pic2val\Pic2Val\Pic2Val\Form1.Designer.cs
     文件        5817  2013-12-18 17:14  Pic2val\Pic2Val\Pic2Val\Form1.resx
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\obj\
     目录           0  2014-03-05 11:10  Pic2val\Pic2Val\Pic2Val\obj\Debug\
     文件        1278  2013-12-18 17:03  Pic2val\Pic2Val\Pic2Val\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略24个文件信息

评论

共有 条评论