Superpose two sets of images

≡放荡痞女 提交于 2019-12-13 01:38:11

问题


I have two sets of images in folder A and folder B. They share common file names. E.g. I have Image01 and Image02 in both the folders.

I need to superpose Image01 from folder A on Image 01 from folder B and so on respectively. Is there a way I can automate this using ImageMagick or batch processing?


回答1:


Assuming your environment is Mac OSX or Linux or Unix...

Then you could this:

for img in A/* ; do        \
   convert                 \
      A/${img}             \
      B/$(basename ${img}) \
     -gravity center       \
     -compose blend        \
     -composite            \
     -alpha set            \
      composed.png         \
done

Now you have to understand: the description of your requirement is very, very unclear. Some questions remain:

  • Do the respective images of the same width/height dimensions?
  • Are they in the same file format? Do they use transparency/alpha channel?
  • How exactly do you want the superimposition to work?

There are a lot of different methods to superpose two images. To see the complete list, look at the output of this command:

convert -list compose

In my installation it shows 67 different methods:

Atop Blend Blur Bumpmap ChangeMask Clear ColorBurn ColorDodge Colorize CopyBlack CopyBlue CopyCyan CopyGreen Copy CopyMagenta CopyOpacity CopyRed CopyYellow Darken DarkenIntensity DivideDst DivideSrc Dst Difference Displace Dissolve Distort DstAtop DstIn DstOut DstOver Exclusion HardLight HardMix Hue In Lighten LightenIntensity LinearBurn LinearDodge LinearLight Luminize Mathematics MinusDst MinusSrc Modulate ModulusAdd ModulusSubtract Multiply None Out Overlay Over PegtopLight PinLight Plus Replace Saturate Screen SoftLight Src SrcAtop SrcIn SrcOut SrcOver VividLight Xor

My example command above uses only one of these, -compose blend.

You need to experiment with the different composition methods to see which one matches your idea. Here is a little illustration which shows you how some of the methods work when applied to two very simple shapes:

Before you start, you could look up and read a bit about the effects of the different methods:

  • Compose tables (above image taken from there)
  • IM examples: compositing images


来源:https://stackoverflow.com/questions/27891367/superpose-two-sets-of-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!