# How to create static alpha masks of an image

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?

• 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). – lightxbulb Sep 29 '19 at 13:17
• Could you please elaborate more on inversing black pixels? – Mark Sep 29 '19 at 13:46
• 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. – lightxbulb Sep 29 '19 at 14:06

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.