检测图像中黑色像素 [英] detecting black pixel in an image

查看:288
本文介绍了检测图像中黑色像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从canvas.drawcircle ..

how i can detect black pixel from a circle drawn by canvas.drawcircle..

canvas.drawCircle((float)(myMidPoint.x - myEyesDistance/2.0), myMidPoint.y, (float)30.0, myPaint);

int x1=(int) (myMidPoint.x) /2;

int y1=(int)(myMidPoint.y)/2;
// int x2=(int) (myMidPoint.x + myEyesDistance/2.0);
// int y2=(int) myMidPoint.y;
int pixelColor = myBitmap.getPixel(x1,y1);
if(pixelColor == Color.BLACK) {
    //The pixel is black
    System.out.println("pixel black");
} else {
    //The pixel was white
    System.out.println("pixel white");
}

我也问过眼前的问题,但没有更新。谁能帮我来说这是非常紧迫的。希望你们能帮助我。 Plzz看到<一个href=\"http://stackoverflow.com/questions/17779843/comparing-pixel-colors-in-a-selected-region\">link

推荐答案

Col​​or.BLACK是重新ARGB十六进制值0xff000000的presentation整数。所以,你的说法是检查在圆圈的中心点是完全一样的透明度,红色值,蓝色值和绿色值Color.BLACK。

Color.BLACK is the integer representation of argb Hex value 0xff000000. So your statement is checking whether a center point in the circle is exactly the same transparency, red value, blue value and green value as Color.BLACK.

有几个选项:

您可以尝试使用只是比较RGB值

You can try comparing just the rgb value by using

if(Color.rgb(Color.red(Color.BLACK), Color.green(Color.BLACK), Color.blue(Color.BLACK) == Color.rgb(Color.red(pixelColor), Color.green(pixelColor), Color.blue(pixelColor))

另外,你可以扫描一个黑色(0x000000处)像素的整个圆。

Alternatively you could scan the entire circle for a black (0x000000) pixel.

另外,您可以使用色差算法,并可以为你所需要的测试不同的公差。这可能会帮助您如何比较两种颜色的。

Alternatively you could use a Color difference algorithm and you can test different tolerances for what you need. This may help you How to compare two colors.

以下尚未经过测试,但会给你一个想法,哪个方向的,你也可以考虑:

The following hasn't been tested, but will give you an idea of which direction you could take also:

//mid points x1 and y1
int x1=(int) (myMidPoint.x) /2;
int y1=(int)(myMidPoint.y)/2;
int radius = 30;
int topPoint = y1 - radius;
int leftPoint = x1 - radius;
int rightPoint = x1 + radius;
int bottomPoint = y1 + radius;
int scanWidth = 0;
for(int i = topPoint; i < bottomPoint; i++) 
{

    if(i <= y1)
    {
        scanWidth++;
    }
    else {
        scanWidth--;
    }
    for(int j = x1 - scanWidth; j < x1 + scanWidth; j++)
    {
        int pixelColor = myBitmap.getPixel(j,i);
        if(Color.rgb(Color.red(Color.BLACK), Color.green(Color.BLACK), Color.blue(Color.BLACK) == Color.rgb(Color.red(pixelColor), Color.green(pixelColor), Color.blue(pixelColor))
        {
            System.out.println("pixel black");
        }
    } 
} 

这篇关于检测图像中黑色像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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