什么是将图像转换为纯黑色和白色在C#中的最快方法是什么? [英] What is the fastest way to convert an image to pure black and white in C#?

查看:915
本文介绍了什么是将图像转换为纯黑色和白色在C#中的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我已经通过其他职位上的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);

        }
    }

    返回输出;

}
 

解决方案

看了这个,同样的问题:<一href="http://stackoverflow.com/questions/2746103/what-would-be-a-good-true-black-and-white-colormatrix">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?

这篇关于什么是将图像转换为纯黑色和白色在C#中的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆