1

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

Ngoc Hoang
  • 11
  • 2

1 Answers1

0

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:

enter image description here

So, realistically, your only hope of salvaging something useful is the alpha (A) channel:

enter image description here

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":

enter image description here

With PIL, that's ImageDraw.floodfill().

Now make everything that is not red become black:

enter image description here

That's easiest with Numpy. See here.

Now make everything that is not red become white:

enter image description here

That's easiest with Numpy.

And make everything that is red become white:

enter image description here

That's easiest with Numpy.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432