1

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=(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");
}

I have asked this question before.

Community
  • 1
  • 1
ayjc
  • 23
  • 6
  • Why not to check every pixel inside the circle area? – sandrstar Jul 24 '13 at 05:52
  • but in canvas it returns void and dont know how to check the pixels there inside canvas...any help plzz im behind this for about one month..i couldn't go further if i could detect the pupil..(see link)can you plzz help me.. – ayjc Jul 24 '13 at 06:03
  • You know circle center and it's radius, right? What is exact problem: to 'map' that info to images' coordinates or to sort out points inside circle? – sandrstar Jul 24 '13 at 06:05
  • center is ok..but i don't know how i could check for black pixels inside the circle..it is to know whether the eyes are opened or not... – ayjc Jul 24 '13 at 06:08
  • comparing rgb value not works well..Any suggestions to scan the entire circle for a black pixel – ayjc Jul 24 '13 at 06:26
  • hm, then you might need to define some 'limits' for black and provide it in the question. – sandrstar Jul 24 '13 at 06:28
  • i would like to limit the black pixel range with in the circle..plzz see the link for the image in the question..it would be nice if i could find black pixel inside the circle..showing the presence of pupil.. – ayjc Jul 24 '13 at 06:49
  • Seems you need DARK pixels, not black and also need to find some % of such pixels inside circles. However, to achieve efficient results You need to do analysis of some open / close eye fotos. – sandrstar Jul 24 '13 at 06:55
  • yes..can you help me in that please.. – ayjc Jul 24 '13 at 06:58

1 Answers1

0

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 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");
        }
    } 
} 
Community
  • 1
  • 1
frogmanx
  • 2,620
  • 1
  • 18
  • 20
  • if i want to scan the entire circle for a black pixel what should i do..how i can access the circle which is drawn by canvas.draw circle – ayjc Jul 24 '13 at 06:11
  • comparing rgb value not works well..Any suggestions to scan the entire circle for a black pixel – ayjc Jul 24 '13 at 06:25
  • 1
    What efficiency are you looking to achieve? I can try and chop out some code for you to try, but it won't be 100% efficient – frogmanx Jul 24 '13 at 06:26
  • the application is actually to detect whether the patient opened his eyes or not..for final implementation 100% efficiency is required..still it would be nice if you can try out something..can you help me in that.. – ayjc Jul 24 '13 at 06:45
  • which one the whole app?? – ayjc Jul 24 '13 at 06:56
  • You can customise it to scan more of a circular range by changing the scanWidth to more of a square root(30 - x^2) function. – frogmanx Jul 24 '13 at 07:00
  • ok let me try out your suggestions..hope i can get back to you if something went wrong.. – ayjc Jul 24 '13 at 07:05
  • Sounds like you're trying to defuse a bomb – frogmanx Jul 24 '13 at 07:08
  • but it provides the same output as your first option – ayjc Jul 24 '13 at 07:21
  • ha ha ha...yes my dear friend..its like the same..as i am totally stuck up there..i tried so many blogs, forums..no one comeout with a productive result..its you finally considered my question..i want to diffuse it anyway that's why..for this i tried opencv..grey scaling of image..black and white..all a complete flop...any way i have to detect the pupil..thanks to Android face detector..but its not as accurate as we want...still in dilemma.. – ayjc Jul 24 '13 at 07:28
  • this will output the black pixels even if the eyes are closed..the eye lids are there!!!gr8 ha ha ha.. – ayjc Jul 24 '13 at 07:59
  • Sounds like a difficult project – frogmanx Jul 24 '13 at 12:09
  • How about comparing how much white space there is to get a better chance of detecting eyes are open. You can use multiple methods and then weight each answer to get the best outcome. – frogmanx Jul 24 '13 at 12:42
  • can you suggest me some good methods...the ultimate aim is to detect the eyes are opened or not from images...will you please help me..anyhow i have to achieve this.. – ayjc Jul 24 '13 at 12:48
  • can you tell me how i could try to sum up the values of pixel values in circle region as the sum value for open eye will be different compared to that of closed.. – ayjc Aug 09 '13 at 07:20