I have an image of following type-
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?
Computer Graphics Stack Exchange is a question and answer site for computer graphics researchers and programmers. It only takes a minute to sign up.
Sign up to join this communityYou 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.
(r+g+b)/3
) is lower than some thresholdT
, 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$