Page 1 of 1

How to subtrack images correctly.

Posted: 2009-05-26T04:46:06-07:00
by test84
Hi,

I have two sets of frame images of a flame, one set is the color image itself and one set is its alpha channel supposedly. Both sets are JPG files.
What I want to do is to build a transparent animated file (or another way instead, what do you think) to use it as a particle system.

here is one frame of each of those sets:

Image

Image

So I have to subtract that alpha picture from the colored one to get the pure picture. I tried this with the images I posted in the first post in ImageMagick but turned to garbage:

the command I executed:
composite -compose subtract source.jpg alpha.jpg newfile.jpg

and the result:

Image

what am I missing here? the process worked with Photoshop, I created an alpha channel in colored picture, copied the alpha picture there, deleted background and voila.

I think I'm missing something with ImageMagick here.

Here is what I wanted:

Image

Re: How to subtrack images correctly.

Posted: 2009-05-26T10:17:46-07:00
by fmw42
First I suggest using the more modern convert syntax as it is more flexible. Second subtract should be minus (subtract has a wrap around and minus does not). Third, you may want to multiply rather than minus. Fourth you may want put the mask into the alpha channel and then convert to jpg or better keep as png as jpg does not have or keep transparency.

see http://www.imagemagick.org/Usage/compose/

Here are the examples:

convert fire.jpg fire_mask.jpg +swap -compose minus -composite -contrast-stretch 0 fire_comp1.jpg
Image

convert fire.jpg fire_mask.jpg -compose multiply -composite fire_comp3.jpg
Image

convert fire.jpg fire_mask.jpg -compose copy_opacity -composite fire_comp2.jpg
Image

convert fire.jpg fire_mask.jpg -compose copy_opacity -composite fire_comp4.png
Image

Re: How to subtrack images correctly.

Posted: 2009-05-27T09:07:25-07:00
by test84
Thanks alot.

My question is, how to generate multiple files? I can read batch files but I can't write them, the syntax I'm using is:

Code: Select all

convert FIR_026%d.jpg[1-4] FIR_026M%d.jpg[1-4] -compose copy_opacity -composite %d.png[1-4]
but that

Code: Select all

-composite %d.png[1-4]
is not generating four files, but just a 0.png . What am I missing here?

Re: How to subtrack images correctly.

Posted: 2009-05-27T09:11:18-07:00
by fmw42
composite can only handle two image as input and not a set of frames as far as I know. so you will have to do a loop in a script for each pair of frames. I will defer to the IM experts for better information

you may be able to do it with alpha composition in mogrify, but that is beyond me. see http://www.imagemagick.org/Usage/basics ... fy_compose

Re: How to subtrack images correctly.

Posted: 2009-05-31T21:50:05-07:00
by anthony
Only one operator can compose two separate sequences of images. I added it to IM to allow easier composition of animations.
Layer Composite
http://www.imagemagick.org/Usage/anim_mods/#composite

Usage is much as you would for two images, but uses a two lists of images separated by a special null: image divider, to mark the end of the first list and the start of the second.

Code: Select all

   convert  'flames_%d.jpg[0-10]' null: 'flames_alpha_%d.jpg[0-10]' \
                 +matte -compose CopyOpacity -layers composite \
                 flames_%d.png
If one of the image lists is a single image, then that image is applied against ALL the images in the other image list.

It is as simple as that!