imagemagickimagemagick-convert

Colorize Specific Regions of an Image Using a Mask with ImageMagick


I'm trying to colorize specific regions of an image based on a mask using ImageMagick. The mask contains white pixels where the image should be colorized and black pixels where no colorization should occur.

The command I've tried:

magick convert input_image.png mask.png -alpha off -compose CopyOpacity -composite -fill "#FF5733" -colorize 100% output_image.png

Problem:

System Info:


Solution

  • Here is one way to do that in Imagemagick. Create a colorized image the size of the input. Then use the mask to composite them together.

    (Don't use magick convert --- use just magick)

    Image:

    enter image description here

    Mask:

    enter image description here

    magick lena.png ( +clone -fill blue -colorize 100 ) mask.png -compose over -composite lena_colorized.png
    

    enter image description here