Skip to content Skip to sidebar Skip to footer

Detecting Black Pixel In An Image

How can I 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=(i

Solution 1:

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.

A few options:

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))

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 for similarity/difference.

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

//mid points x1 and y1int x1=(int) (myMidPoint.x) /2;
int y1=(int)(myMidPoint.y)/2;
intradius=30;
inttopPoint= y1 - radius;
intleftPoint= x1 - radius;
intrightPoint= x1 + radius;
intbottomPoint= y1 + radius;
intscanWidth=0;
for(inti= topPoint; i < bottomPoint; i++) 
{

    if(i <= y1)
    {
        scanWidth++;
    }
    else {
        scanWidth--;
    }
    for(intj= x1 - scanWidth; j < x1 + scanWidth; j++)
    {
        intpixelColor= 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");
        }
    } 
} 

Post a Comment for "Detecting Black Pixel In An Image"