Page 1 of 1

tiff stacks in the Image Calculator

Posted: 2010-01-21T12:21:50-07:00
by thk
Hi, I have to manipulate large tiff stacks for which I right now use a program with a cumbersome graphical interface, so I was hoping to make my life easier with IM. I already managed to crop tiff stacks, showing me that IM in principle can handle them, but I didn't figure out how to address a certain layer of the stack when using the image calculator (convert -fx). As an example, I have a stack example.tif of 400 layers and I want to calculate the average of the say 5th and 8th layer. 'convert example.tif -depth 8 -fx "(u[4]+8[7])/2.0" average.tif' just gives me a black image back.

Re: tiff stacks in the Image Calculator

Posted: 2010-01-21T14:06:40-07:00
by fmw42
perhaps a type
convert example.tif -depth 8 -fx "(u[4]+8[7])/2.0" average.tiff

try
convert example.tif -depth 8 -fx "(u[4]+u[7])/2.0" average.tiff

or
convert example.tif[4] example.tif[7] -depth 8 -fx "(u[0]+u[1])/2.0" average.tiff

Re: tiff stacks in the Image Calculator

Posted: 2010-01-22T01:49:34-07:00
by thk
the '8[7]' was a typo in my original post, I used 'u[7]' in the bash shell :). Also,

convert example.tif[4] example.tif[7] -depth 8 -fx "(u[0]+u[1])/2.0" average.tiff

does not do the trick either.

Re: tiff stacks in the Image Calculator

Posted: 2010-01-22T02:20:58-07:00
by thk
Ok, I figured it out. The problem was not with IM, but with the tifflib. There was an unknown tag in the tiff file, namely TIFFFieldWithTag (0x697), apparently a special tiff tag that the program ImageJ adds to all tiff files. Encountering the tag somehow caused an error and led to the unwanted result. I got rid of the problem by using the command

tiffcp original.tif copy.tif

which apparently duplicates the image, but removes all tags that are unknown to the tifflib (can be checked with 'tiffinfo file.tif') and afterwards the command

convert stack.tif -depth 8 -fx "(u[4]+u[7])/2.0"

worked just fine.

thank you for the help.