Page 1 of 2

MIP- maximum intensity projection

Posted: 2010-03-04T18:02:19-07:00
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.

Re: MIP- maximum intensity projection

Posted: 2010-03-04T18:12:28-07:00
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).

Re: MIP- maximum intensity projection

Posted: 2010-03-04T18:41:51-07:00
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

Re: MIP- maximum intensity projection

Posted: 2010-03-05T02:26:14-07:00
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

Re: MIP- maximum intensity projection

Posted: 2010-03-05T09:40:48-07:00
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.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T10:13:15-07:00
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.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T10:57:17-07:00
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 ?

Re: MIP- maximum intensity projection

Posted: 2010-03-05T11:13:59-07:00
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.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T11:35:05-07:00
by magick
+mip computes the minimum, -mip computes the maximum intensity projection.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T12:02:07-07:00
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?

Re: MIP- maximum intensity projection

Posted: 2010-03-05T12:30:05-07:00
by magick
It turns out we're going to use -intensity-projection / +intensity-projection instead of -mips.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T13:01:18-07:00
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.

Re: MIP- maximum intensity projection

Posted: 2010-03-05T14:45:41-07:00
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

Re: MIP- maximum intensity projection

Posted: 2010-03-05T16:25:32-07:00
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...

Re: MIP- maximum intensity projection

Posted: 2010-03-05T16:56:28-07:00
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