Imagemagick: Mask mutliple images using black-and-white mask

120 Views Asked by At

I have a series of black-and-white images, like this:

Source image

ImageMagick converts thems to mask, using connected-components

magick *.png -define connected-components:area-threshold=130 -define connected-components:mean-color=true -connected-components 8 -negate mask\mask-%02d.png

Mask

After that I'd like to apply this masks to original images and get images without grid lines.

How to do this using one ImageMagick command? I have the series of images, not one.

1

There are 1 best solutions below

8
Mark Setchell On BEST ANSWER

One way might be to composite the two images together choosing the darker of the two at each pixel location:

magick aaeDd.png Sf07q.png -compose darken -composite result.jpg

enter image description here


If you want to do all steps in a single command, you can use:

magick aaeDd.png \
  \(                                                 \
     +clone                                          \
     -define connected-components:area-threshold=130 \
     -define connected-components:mean-color=true    \
     -connected-components 8 -negate                 \
  \) -compose darken -composite result.jpg