tiff stacks in the Image Calculator
tiff stacks in the Image Calculator
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: tiff stacks in the Image Calculator
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
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
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.

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
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.
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.