1
$\begingroup$

I have an image of following type- enter image description here

I want to create mask of the following type where the inside area is white and rest of it is black. How to do it? enter image description here

$\endgroup$
3
  • $\begingroup$ Again - edge detection. Or you can take out all perfectly black pixels and use those as an inverse to the mask (in this specific image it seems like it will work). $\endgroup$
    – lightxbulb
    Sep 29, 2019 at 13:17
  • $\begingroup$ Could you please elaborate more on inversing black pixels? $\endgroup$
    – Mark
    Sep 29, 2019 at 13:46
  • $\begingroup$ Let's assume you create a new image which is black everywhere where the greyvalue (for example (r+g+b)/3) is lower than some threshold T, and white otherwise. So essentially: target(x,y) = dot(source(x,y),vec3(1)) < 3.0*T ? 1 : 0 Where you loop over all pixels. $\endgroup$
    – lightxbulb
    Sep 29, 2019 at 14:06

1 Answer 1

1
$\begingroup$

You can either use a threshold, or, since you know the location and size of the 2 circles, simply generate one programatically. In this case, you have a circle that's centered at (279, 283.5) and has a radius of 265. (I haven't calculated the center and radius of the smaller circle, but you should be able to do that fairly easily by looking at the image in any image editor that shows you mouse coordinates.)

Once you have the smaller circle radius, for each pixel in the mask find the distance to the large circle center and if it's less than the large radius, color it white. Otherwise take the distance to the smaller circle and if it's less than the smaller radius, color it white. Otherwise, color it black.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.