什么是将图像转换为纯黑色和白色在C#中的最快方法是什么?转换为、图像、白色、黑色

2023-09-04 11:57:26 作者:抱爱半遮面

在别人的火焰我没有检查其他职位,我已经做到了。我有一个具体问题有关的存在将图像转换为灰度的技术之一。

我已经通过其他职位上的SO,基本上复制技术3(嘉洛斯)从教程在的这个网站。它的工作原理非常,非常,很快。

我遇到的问题是,我需要的是一个纯粹的BW图像。 (即:如果平均(R,G,B)> 200 =>其他白黑)。我已经实现了它简单的方法,它实际上需要近10倍,只要从教程灰度算法。

我与图像处理方面的专家,并想知道是否有什么办法可以修改的代码片段教程将图像转换为纯黑色和白色。如果不是这样,任何有效的方式会做。

编辑:

这里的code,我使用了黑色和白色(无脑的做法):

 公共位图make_bw(位图原件){

    位图输出=新位图(original.Width,original.Height);

    的for(int i = 0; I< original.Width;我++){

        对于(INT J = 0; J< original.Height; J ++){

            颜色C = original.GetPixel(I,J);

            INT平均=((C.R + C.B + C,G)/ 3);

            如果(平均&所述; 200)
                output.SetPixel(I,J,Color.Black);

            其他
                output.SetPixel(I,J,Color.White);

        }
    }

    返回输出;

}
 

解决方案

看了这个,同样的问题:What将是一个很好的纯黑和白色嘉洛斯?

请问什么软件可以修改图片阈值,把图片变成纯黑白的那种就像下图,要怎么操作谢谢

Before someone flames me for not checking the other posts, I have done that already. I have a specific question about one of the techniques that exist to convert an image to grayscale.

I have read through the other posts on SO and basically copied technique 3 (ColorMatrix) from the tutorial at this site. It works very, very, quickly.

The problem I'm having is that what I need is a pure BW image. (i.e.: if average(R,B,G) > 200 => white else black). I have implemented it the straightforward way, and it actually takes nearly 10x as long as the grayscale algorithm from the tutorial.

I am no expert with image processing, and was wondering if there is any way to modify the snippet from the tutorial to convert images to pure black and white. If not, any efficient way would do.

EDIT:

Here's the code I'm using for the black and white (no brain approach):

public Bitmap make_bw(Bitmap original) {

    Bitmap output = new Bitmap(original.Width, original.Height);

    for (int i = 0; i < original.Width; i++) {

        for (int j = 0; j < original.Height; j++) {

            Color c = original.GetPixel(i, j);

            int average = ((c.R + c.B + c.G) / 3);

            if (average < 200)
                output.SetPixel(i, j, Color.Black);

            else
                output.SetPixel(i, j, Color.White);

        }
    }

    return output;       

}

解决方案

Read this, same problem: What would be a good TRUE black and white colormatrix?

 
精彩推荐
图片推荐