I'm trying convert to white or transparent some rectangles areas within the below image.
I'm able to make it with ImageMagick with the following command, that first makes transparent desired colors and finally convert to black the rest with "negate".
convert input.png \
-transparent '#4B8DF8' \
-transparent '#27A9E3' \
-transparent '#2295C9' \
-transparent '#E7191B' \
-transparent '#C91112' \
-transparent '#28B779' \
-transparent '#17A769' \
-transparent '#852B99' \
-transparent '#751E88' \
-transparent '#D84A38' \
-transparent '#B4CEF8' \
-transparent '#17A76A' \
-transparent '#CA1112' \
-transparent '#2296CA' \
-transparent '#DDE8FA' \
-alpha extract -negate out_convert.png
The Python/Wand script I have so far is this:
from wand.image import Image
with Image(filename='input.png') as img:
img.transparent_color('#4B8DF8', alpha=0.0)
img.transparent_color('#27A9E3', alpha=0.0)
img.transparent_color('#2295C9', alpha=0.0)
img.transparent_color('#E7191B', alpha=0.0)
img.transparent_color('#C91112', alpha=0.0)
img.transparent_color('#28B779', alpha=0.0)
img.transparent_color('#17A769', alpha=0.0)
img.transparent_color('#852B99', alpha=0.0)
img.transparent_color('#751E88', alpha=0.0)
img.transparent_color('#D84A38', alpha=0.0)
img.transparent_color('#B4CEF8', alpha=0.0)
img.transparent_color('#17A76A', alpha=0.0)
img.transparent_color('#CA1112', alpha=0.0)
img.transparent_color('#2296CA', alpha=0.0)
img.transparent_color('#DDE8FA', alpha=0.0)
img.negate()
img.save(filename='out_python.png')
And below I show the output I get using convert
command (only black and white) and the output with python/wand
script (it still has some other colors beside black and white).
What is missing in my script in order to get the same output as I get with ImageMagick? Is Wand a good python library for this or could be done with another one?