I have a transparent image transparent image
I tried use Pillow convert("L") but it doesn't get all the pixels inside the rounded rectangle.
I want to create a mask like this ( include all pixels inside the rounded rectangle) mask
I have a transparent image transparent image
I tried use Pillow convert("L") but it doesn't get all the pixels inside the rounded rectangle.
I want to create a mask like this ( include all pixels inside the rounded rectangle) mask
Sadly you appear to be to be starting off with a particularly poorly designed image. If we separate it into its RGBA channels, (R on the left, A on the right) with a yellow background, we see:
So, realistically, your only hope of salvaging something useful is the alpha (A) channel:
With PIL, that's getchannel('A')
.
Let's fill starting from each of the 4 corners and the first column halfway down the left edge with red using "flood fill":
With PIL, that's ImageDraw.floodfill()
.
Now make everything that is not red become black:
That's easiest with Numpy. See here.
Now make everything that is not red become white:
That's easiest with Numpy.
And make everything that is red become white:
That's easiest with Numpy.