Superpose two sets of images - imagemagick

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?

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

Related

Imagemagick: Create 1 image out of 3 with luminance/overlay mask

I want to generate an image out of 3 images. One of these images is the background, one the shape mask and one the color of the shape.
Here are the images:
shape.png
(transparent background, white circle in the middle and black circle inside and gray circle inside the black one)
shapecolor.png
background.png
The background.png should be the overall background. On top of that is the shape and all white parts (and also the white in the gray parts) should be in the color of shapecolor.png
I used simple mono color images to make it easier but I use some textures in reality ^^
I have no idea how to solve this problem in Imagemagick, the tool is very powerful and the documentation is not so easy to understand. Tried to solve this for 3h, but did not get the result, which should look like this:
Can anyone help please?
Here is one way to do it in Imagemagick. In the second line, extract the alpha channel from omg.png and save it in an mpr: in-memory image and then delete the clone. Then I use the mpr: image later in the last step.
convert red.png img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-compose multiply -composite \
green.png +swap mpr:alpha -compose over -composite \
result.png

ImageMagick: Distort and Overlay

I have several pictures of a landscape.
Using the ImageMagick CLI on OSX, I would like to distort and overlay them properly.
I have looked for distortion coordinates between several of the pictures and a reference picture. I fail to understand the diference between -distort and +distort and how it plays with +repage. When I use -distort, the output has the desired offset but it's incomplete (it needs to be bigger). When I use +distort, I get the full image but it's missing the offset.
Reading the documentation I understand that I could do without the offset if I did the overlay composition in the same command before the offset information is lost but what's happening is that the distort is being applied to both the reference and the distorted images.
This is the result of using -distort:
This is the result of using +distort:
The offset of the -distort result would work once I apply it as an overlay (here using the composite in a separate command, but it's missing a big chunk of the picture.
When I tried to consolidate it in a single command this is the result I get:
This is the command I'm currently using:
convert base.jpg overlay.jpg
-matte -virtual-pixel transparent -distort Perspective '961,1695 1856,2461 2279,1520 3185,2303 3564,2173 4441,2970 1547,2817 2441,3594'
-compose blend -define compose:args=50,100 -composite result.jpg
I understand I could use parenthesis there but I fail to see where should I put them.
Thanks!
Update: this is the result of the overlay when using +distort either in two steps or in a single step as recommended by Mark.
The solution was to use -flatten instead of -composite.
convert base.jpg \( b.jpg -matte -virtual-pixel transparent +distort Perspective '961,1695 1856,2461 2279,1520 3185,2303 3564,2173 4441,2970 1547,2817 2441,3594' \) -compose blend -define compose:args=100,50 -flatten result.jpg
Turns out that -composite ignores the image offsets whereas -flatten works with layers and uses the offset information.
The suggestion came from this thread: http://www.imagemagick.org/discourse-server/viewtopic.php?t=20157
This is the documentation to flatten (link broken in the discussion above): http://www.imagemagick.org/Usage/layers/#flatten
Not sure I understand the issues, but would suggest you try this (untested):
convert base.jpg \
\( overlay.jpg -matte -virtual-pixel transparent -distort Perspective '961,1695 1856,2461 2279,1520 3185,2303 3564,2173 4441,2970 1547,2817 2441,3594' \) \
-define compose:args=50,100 -compose blend -composite result.jpg
That would mean that the perspective distortion is only applied to the overlay, not the base. So, in the code above, the first line only processes the base image, the second line only processes the overlay, and the final line blends the two.

For Imagemagick, how can I stop the "montage -tile 3x3" command from cropping the output?

I take an image and chop it into 9 equally size tiles. Each tile is run through a process that increases it's resolution. All 9 tiles slightly overlap each other based on a specific hard-coded value.
The issue however is that when the modified tiles are put back together into the original image. ImageMagick seems to crop the new output made of the modified tiles. All the tiles appear to be perfectly positioned, and thus I can't figure out why ImageMagick crops the final output, let alone how I can stop it.
This is the original image before it's chopped into 3x3 overlapping tiles:
https://i.imgur.com/TPWygd0.jpg
This is the final output composed of the modified tiles:
https://i.imgur.com/8ENBJsw.jpg
How can I prevent ImageMagick from cropping this output?
The code used to put the modified tiles back together, is shown below:
# 6. merge feathered tiles
montage $feathered_dir/$clean_name'_0.png' $feathered_dir/$clean_name'_1.png' \
$feathered_dir/$clean_name'_2.png' $feathered_dir/$clean_name'_3.png' \
$feathered_dir/$clean_name'_4.png' $feathered_dir/$clean_name'_5.png' \
$feathered_dir/$clean_name'_6.png' $feathered_dir/$clean_name'_7.png' \
$feathered_dir/$clean_name'_8.png' -tile 3x3 -geometry -$border_w-$border_h $output/$clean_name.large_feathered.png
# 7. merge un-feathered tiles
montage $tiles_dir/$clean_name'_0.png' $tiles_dir/$clean_name'_1.png' \
$tiles_dir/$clean_name'_2.png' $tiles_dir/$clean_name'_3.png' \
$tiles_dir/$clean_name'_4.png' $tiles_dir/$clean_name'_5.png' \
$tiles_dir/$clean_name'_6.png' $tiles_dir/$clean_name'_7.png' \
$tiles_dir/$clean_name'_8.png' -tile 3x3 -geometry -$border_w-$border_h $output/$clean_name.large.png
This command reproduces the same issue:
montage IMG_3926_0.png IMG_3926_1.png IMG_3926_2.png IMG_3926_3.png IMG_3926_4.png IMG_3926_5.png IMG_3926_6.png IMG_3926_7.png IMG_3926_8.png -tile 3x3 -geometry -68.8151-68.8151 out_correct_geometry.png
Edit:
I posted this issue on the ImageMagick forums here: imagemagick.org/discourse-server/viewtopic.php?f=1&t=31221
The solution to the problem can be found here: https://imagemagick.org/discourse-server/viewtopic.php?f=1&t=31221&p=141729

Two-step watermark applying using imagemagick

I am trying to apply watermark to an image of any size using two steps in one command line:
Tile small png image and overlay it over the target image.
Overlay a logo at top left corner without tiling.
I don't understand the imagemagick command line principles and can't create a command line to make these operations without creatig temporary file between steps 1 and 2. But I am sure this is possible :)
Please help me to do that.
Thanks.
There are many ways to achieve this, but the simplest would be to leverage ImageMagick's Stack notation "()".
Simply group the first step into a command wrapped in parentheses, and omit the output filename.
convert \( \
wizard: \
-size 480x640 \
-background transparent \
tile:label.png -composite \
\) \
-gravity NorthEast rose: \
-composite output.png
The above will compose the label.png as a repeating image over the wizard: image. Note, in this example I provided the -size and -background attributes. The result of the Image Stack will be accepted as the input image for the second -composite operation; which, places the rose: image in the top right.

Export Multiple PSD Layer file to PNG while applying tint effect to each layer

We have the following PSD
https://app.box.com/s/rf514j3wnic1xkt6y1q3b5qnk0zds2rl
This is a transparent PSD with one base layer for the ring metal.
And additional layer for each individual stones.
Something like https://app.box.com/s/i8lhshbl27pvjmmczjq2bhla4mzw9cwn
and this
We want to be able to apply tint to each individual stone layer based of user input and export the final image as PNG file. To provide users the ability to design the ring to their liking.
Now I am trying to figure out what is the best way to achieve this functionality ?
We would like the image generated server side in .net so it can be shared.
What is the best way to approach this. I am thinking of using an image library like imagemagick to convert the image.
But I am unable to locate any examples where you can alter multiple layer with in a PSD file before converting it to another file format.
Any example or suggestion on methods to achieve this will of great help.
Editing layered PSD files is not going to be easy. I would suggest you maybe save the ring and each of the gemstone layers as a separate PNG file. Then you can do something along these lines with ImageMagick:
#!/bin/bash
convert ring.png \
\( layer-1.png \( +clone +level-colors red \) -compose Multiply -composite \) -compose overlay -composite \
\( layer-2.png \( +clone +level-colors green \) -compose VividLight -composite \) -compose overlay -composite \
\( layer-3.png \( +clone +level-colors blue \) -compose LinearBurn -composite \) -compose overlay -composite \
\( layer-4.png \( +clone +level-colors "#ffff00" \) -compose Saturate -composite \) -compose overlay -composite \
result.png
Giving you a PNG file like this:
You may like to experiment with the blending modes, I just tried a few that looked vaguely pleasing to my eye. If you want a list of all available blending modes, you can do:
identify -list compose
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
I also specified some colours by name and one by hex, so you can see how to do it that way if you prefer.
P.S. If you keep all your artwork as PSD files, you can always use Adobe's ExtendScript to script the export of the various layers as separate PNG files with a single keypress...
P.P.S. It is possible for ImageMagick to extract the layers from a PSD file itself, but I extracted the layers from your file and they are not all the same size as the background image and I cannot find their correct positioning relative to it. If you know something about how the layers were created and whether they could be made identical size and aligned with the background, you could replace layer-n.png in my examples with PhotoshopFile.psd[n]
P.P.P.S. If you want to do this server side in .NET you should take a look at the .NET library for ImageMagick that can be found here: https://magick.codeplex.com/. If you need help translating the commands above to C# you could ask a question on the discussions page there.

Resources