<p>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.)</p>

<p>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.</p>

CC BY-SA 4.0
2019-09-29T20:33:07.340Z
2019-09-29T20:33:07.340Z
user1118321
<p>I have an image of following type-
<a href="https://i.sstatic.net/ayESL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ayESL.png" alt="enter image description here"></a></p>

<p>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?
<a href="https://i.sstatic.net/NzDB9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NzDB9.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-09-29T13:17:50.397Z
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
CC BY-SA 4.0
2019-09-29T13:46:34.393Z
Could you please elaborate more on inversing black pixels?
Mark
CC BY-SA 4.0
2019-09-29T14:06:18.540Z
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
<image-processing><image>
How to create static alpha masks of an image
Mark
# How to create static alpha masks of an image

(Asked by: username_0 on 2019-09-29)

I have an image of following type-
[![enter image description here](https://i.sstatic.net/ayESL.png)](https://i.sstatic.net/ayESL.png)

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](https://i.sstatic.net/NzDB9.png)](https://i.sstatic.net/NzDB9.png)

**Tags:** image-processing, image

> **Comments:**
> **username_1**: 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).  
> **username_0**: Could you please elaborate more on inversing black pixels?  
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2019-09-29. Score: 1 | Accepted answer

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.


---

