图像处理在C# - 一个聪明的解决方案吗?

问题描述:

我有它的字母图像,字母有两种颜色黑色和蓝色,我想读从图像中蓝色的字母。

I have an image with letters in it, the letters are in two colors black and blue, I want to read the blue colored letters from the image.

灿有人建议我在C#中做到这一点的方法。 IAM学习GDI +,但仍然没有得到任何的逻辑来制定这一计划。

Can anyone suggest me a method to do this in C#. Iam studying GDI+,but still didn't get any logic to develop this program..

我试过OCRing,但与普通光学字符识别的问题是,他们不承认色差。

I tried OCRing it, but the issue with common OCRs is that they dont recognize the color difference.

我只是想读的蓝字....

I only want to read the Blue characters....

任何指导的高度赞赏

试试这个;),但是,这是不安全的代码。

Try this one ;) But that's unsafe code.

void RedAndBlue()
{

    OpenFileDialog ofd;
    int imageHeight, imageWidth;

    if (ofd.ShowDialog() == DialogResult.OK)
    {
    	Image tmp = Image.FromFile(ofd.FileName);
    	imageHeight = tmp.Height;
    	imageWidth = tmp.Width;
    }
    else
    {
    	// error
    }

    int[,] bluePixelArray = new int[imageWidth, imageHeight];
    int[,] redPixelArray = new int[imageWidth, imageHeight];
    Rectangle rect = new Rectangle(0, 0, tmp.Width, tmp.Height);
    Bitmap temp = new Bitmap(tmp);
    BitmapData bmpData = temp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
    int remain = bmpData.Stride - bmpData.Width * 3;
    unsafe
    {
    	byte* ptr = (byte*)bmpData.Scan0;
    	for (int j = 0; j < bmpData.Height; j++)
    	{
    		for (int i = 0; i < bmpData.Width; i++)
    		{
    			bluePixelArray[i, j] = ptr[0];
    			redPixelArray[i, j] = ptr[2];
    			ptr += 3;
    		}
    		ptr += remain;
    	}
    }
    temp.UnlockBits(bmpData);
    temp.Dispose();
}