0

I have an image, coming out of a scan, that I would like to reproduce it in several different colors against multiple different colored backgrounds, like the one bellow:

enter image description here

I can easily change the color of the bug with level-color conversion, as in:

convert image.png +level-colors red, red-image.png

and produce an stupendously good quality image:

enter image description here

I understand (from many postings here) that making the background color transparent in a scan is one of the most difficult operations on an image. My question is:

Is there a way to change the background color -- by level -- in a similar way?

1 Answer 1

3

In ImageMagick, you can recolor the background using -fill ... -opaque. Measure the color of the background, then

convert insect.png -fuzz 5% -fill skyblue -opaque "rgb(235,215,186)" insect_blue.png

enter image description here

The -fuzz X% permits coloring of close but not exactly the measured color. This allows non-uniform background color to be changed. The larger the X%, the more it will color parts of the image.

A value of 0% means only color the exact value measured.

See https://legacy.imagemagick.org/Usage/color_basics/#opaque

2
  • Fred, can one make it background-transparent using a similar trick?
    – Paulo Ney
    Commented Jan 2, 2021 at 16:43
  • Yes, use -channel rgba -fill none So for this image. convert insect.png -fuzz 5% -channel rgba -fill none -opaque "rgb(235,215,186)" insect_trans.png You can also use -fill transparent in place of -fill none
    – fmw42
    Commented Jan 2, 2021 at 17:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.