MIP- maximum intensity projection

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

MIP- maximum intensity projection

Post by alosca »

I use convert -fx "max(max(...(max(u[0],u[1]), u[2])...)" to compute the MIP (max intensity projection) of a series of 8-bit grayscale images. It seems to work OK but it is slow. Any other suggestion of using IM to render faster solutions ? I tried `max(u[0],u[1],u[2],...,u[N])` but it doesn't produce the expect result.
Thanks,
- Alex.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MIP- maximum intensity projection

Post by magick »

The -fx option is interpreted and therefore slow. You can get some speed up by running it on a multi-core system (e.g. a quad-processor).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

try

convert image1 image2 image3 ... imageN -compose lighten -composite maxresult

If this does not work, then do them in successive pairs as

convert image1 image2 -compose lighten -composite \
image3 -compose lighten -composite \
...
imageN -compose lighten -composite maxresult


see http://www.imagemagick.org/Usage/compose/#lighten
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: MIP- maximum intensity projection

Post by alosca »

-compose lighten gives a much faster solution. thanks! the first form above, i.e.,
convert image1 image2 image3 ... imageN -compose lighten -composite maxresult
doesn't work.

here is a simple mip.csh file that did the trick for me:

#!/bin/csh
#
# computes maximum intensity projection of images listed in file $1.
#
set img = `cat $1`
set expr = "composite $img[1-2] -compose lighten -"
foreach f ( $img[3-] )
set expr = "$expr | composite - $f -compose lighten -"
end
eval $expr
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MIP- maximum intensity projection

Post by magick »

We added a -mip option to ImageMagick-6.6.0-3 Beta to return the maximum intensity project of an image sequence. It patch will be available by sometime tomorrow.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

magick wrote:We added a -mip option to ImageMagick-6.6.0-3 Beta to return the maximum intensity project of an image sequence. It patch will be available by sometime tomorrow.

I was under the impression that

convert image1 image2 image3 ... imageN -compose lighten -composite maxresult

would work.

Magick, Is this a bug? Or am I mistaken in that it can only work with two images. It does not object to more than three images. I believe that Anthony told me that it would with multiple images. And the same with -compose darken.
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: MIP- maximum intensity projection

Post by alosca »

when i tried convert didn't complain running -compose lighten/darken with multiple images but the result is if i was running with the first two images only. if it *does work* then this is indeed the call to have MIP.
magick, would the -mip be any better ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

alosca wrote:when i tried convert didn't complain running -compose lighten/darken with multiple images but the result is if i was running with the first two images only. if it *does work* then this is indeed the call to have MIP.
magick, would the -mip be any better ?

Yes, that was the conclusion I formed that it was only using the first two images. But I have a recollection, which could be wrong, that Anthony told me it would work with more that just two (or even 3) images. But I could be wrong. So I am just asking for confirmation whether that is the case that it should work with multiple images and thus a bug or if it was never intended to work with more than two images and then it should complain or warn about more than two images.

In either case, it might be better to change the behaviour of -compose lighten and darken so that one will get the max or min of the sequence of images. Or add an argument to -mip so that it can compute either the max or min of all the images, if -compose lighten and darken cannot easily be modified to handle more images.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MIP- maximum intensity projection

Post by magick »

+mip computes the minimum, -mip computes the maximum intensity projection.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

magick wrote:+mip computes the minimum, -mip computes the maximum intensity projection.
thanks, that makes sense. great!

but what about my question about using multiple images (>2) with -compose lighten?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MIP- maximum intensity projection

Post by magick »

It turns out we're going to use -intensity-projection / +intensity-projection instead of -mips.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MIP- maximum intensity projection

Post by magick »

Composite only accepts 2 or 3 images (image1, image2, mask). You can composite as many images as you want with the convert command by repeating the -compose operator.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

magick wrote:Composite only accepts 2 or 3 images (image1, image2, mask). You can composite as many images as you want with the convert command by repeating the -compose operator.

Yes, thanks. I was not sure that applied to -compose lighten and darken. I thought at one time Anthony mentioned that it could handle multiple images. Thanks for the clarification. I must be remembering wrong.

But after each -compose plus or minus the result gets clipped. My request for -weighted-sum allows me to add and subtract multiple images with positive and negative weights without the clip until the result is returned. But I can wait until you can find some time to get to it.

Thanks

Fred
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: MIP- maximum intensity projection

Post by alosca »

magick wrote:It turns out we're going to use -intensity-projection / +intensity-projection instead of -mips.
for the sake of clarity wouldn't be better to have -mip be minimum and +mip maximum ? i don't know why but it seems our brain makes us associate - with min and + with max; it would be easier to memorize this way. just a thought...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: MIP- maximum intensity projection

Post by fmw42 »

This seems to be working properly in IM 6.0.0-3 beta Q16 Mac OSX Tiger (all images are 128x128 some color and some grayscale)

convert checks.jpg lena2.jpg mandril.jpg peppers2.jpg zelda3.jpg -intensity-projection tmp.png

produces the max at each pixel from all the images.

convert checks.jpg lena2.jpg mandril.jpg peppers2.jpg zelda3.jpg +intensity-projection tmp2.png

produces the min at each pixel from all the images.

The minus vs plus switch would be OK with me so that minus was min and plus was max. But I can live with it either way.

But why not just use the names -min and -max for these functions?

intensity-projection means little to me in understanding what these functions do. But min and max are pretty obvious.



Fred
Post Reply