Page 1 of 1
Convert images from two lists
Posted: 2011-02-25T09:36:59-07:00
by slowhand1980
I'm new to imagemagick, I'm using ImageMagick 6.6.7-9 Q16 version.
Finally I was able two averaging a set of images with the command
Code: Select all
convert -average image*.jpg output.jpg
Now I would to know if is it possiblo to convert, automatically, images from two different sets, somthing that can automate this:
Code: Select all
convert -average x1.jpg y1.jpg xy1.jpg
convert -average x2.jpg y1.jpg xy2.jpg
convert -average x3.jpg y1.jpg xy3.jpg
convert -average x4.jpg y1.jpg xy4.jpg
....
convert -average xn.jpg y1.jpg xyn.jpg
if I were working in java I would have done simething like this:
Code: Select all
for (i=1; i<imagenumber; i++){
convert -average xi.jpg yi.jpg xyi.jpg
}
is it possible?
thanks
Re: Convert images from two lists
Posted: 2011-02-25T11:01:39-07:00
by fmw42
convert -average image*.jpg output.jpg
Proper syntax has the input images first
convert image*.jpg -average output.jpg
also -average is deprecated in favor of -evaluate-sequence average
With regard to using lists, IM can take lists of input images, but not the way you want them as far as I know. You can use the @file.txt as input to IM such as:
convert @file.txt -average output.jpg
That takes all images in file1.txt as input.
I don't know that you can take one image from each list without using shell scripting. As far as I know there is no way to index into a list directly within IM for doing what you want.
Re: Convert images from two lists
Posted: 2011-02-25T15:05:38-07:00
by slowhand1980
can someone help me to create a shell script like this one in Java?
Code: Select all
for (i=1; i<imagenumber; i++){
convert -average xi.jpg yi.jpg xyi.jpg
}
Re: Convert images from two lists
Posted: 2011-02-25T15:59:43-07:00
by anthony
slowhand1980 wrote:Now I would to know if is it possiblo to convert, automatically, images from two different sets, somthing that can automate this:
Code: Select all
convert -average x1.jpg y1.jpg xy1.jpg
convert -average x2.jpg y1.jpg xy2.jpg
convert -average x3.jpg y1.jpg xy3.jpg
convert -average x4.jpg y1.jpg xy4.jpg
....
convert -average xn.jpg y1.jpg xyn.jpg
A slightly tricky solution...
Code: Select all
convert x*.jpg null: y*.jpg -compose blend -define compose:args=50x50 -layers composite z%d.jpg
I did not use 'xy' for the output so as to not muck up image reading (the "x*.jpg") when repeating the above command.
See Layers Composition for composition with two image lists
http://www.imagemagick.org/Usage/anim_mods/#composite
And Blend for weighted addition composition (average = 50x50 composition)
http://www.imagemagick.org/Usage/compose/#blend
One point ALL the images will be in memory at some point, so watch your memory limits, or IM will swicth to a VERY slow disk caching method.
Another alturnative is to 'append' all the images into two single images, average (or whatever), then tile crop them back into individual images. I have used this technique in the past to to do things like: a 'difference' of two animations, to append two image sequences, generate common color maps or count up all unique color over all images, etc..
Re: Convert images from two lists
Posted: 2011-02-25T16:13:35-07:00
by slowhand1980
thank yu so much, by the way I've solved with this script:
Code: Select all
#!/bin/bash
for((i=0; i<10; i++)); do
touch file$i.log
convert x$i.jpg y$i.jpg -evaluate-sequence Mean xy$i.jpg
done
thanks to you now I can try also with this one
Code: Select all
#!/bin/bash
for((i=0; i<10; i++)); do
touch file$i.log
convert x$i.jpg null: y$i.jpg -compose blend -define compose:args=50x50 -layers composite z$i.jpg
done
Re: Convert images from two lists
Posted: 2011-02-25T17:13:08-07:00
by anthony
slowhand1980 wrote:thanks to you now I can try also with this one
Code: Select all
#!/bin/bash
for((i=0; i<10; i++)); do
touch file$i.log
convert x$i.jpg null: y$i.jpg -compose blend -define compose:args=50x50 -layers composite z$i.jpg
done
No need for loop with -layers composite. It merges two sequences (separated by null:) together.
Assuming you do not have xy*.jpg images in the current directory!
Code: Select all
convert x*.jpg null: y*.jpg -compose blend -define compose:args=50x50 -layers composite z%d.jpg
If you were using a loop this is the simpler two image (rather that tw image sequence) composition
Code: Select all
convert x$i.jpg y$i.jpg -compose blend -define compose:args=50x50 -composite z$i.jpg
No null: and no layers.
Re: Convert images from two lists
Posted: 2011-02-26T07:54:08-07:00
by slowhand1980
Can you explain the "null:" function?
Re: Convert images from two lists
Posted: 2011-02-26T20:55:03-07:00
by anthony
It just generates a 'special' image that is generally used as place holders
For example in "montage" a null: image creates a blank tile in the montage output.
It is also a 'marker' for 'null results' such as when a -crop misses the actual image generating a invalid result.
In -layers composite it is used to mark the end of the destination image sequence, and the start of the source image sequence. What the two sequences are then 'composed' together in pairs, until all the image of one sequence runs out. If one of those sequences is a single image, that image is composed with all the other images in the other image sequence. That is whay a loop is not needed, as IM will loop though all the images in memory.
ASIDE: The composition understand -geometry and -gravity for 'global' positioning of the source image sequence (according to its virtual canvas), while image virtual offsets position individual images relative to that virtual canvas position.