Page 1 of 1

Tiff file with signed 32-bit samples

Posted: 2011-12-19T12:19:04-07:00
by BruceRavel

I have in front of me a data set consisting of tiff files containing 32 bit signed integer samples. (I am aware that is an unusual sample type for a tiff file -- the images come in this format from a fancy X-ray detector.) A simple program using Image::Magick has no trouble reading these files and returns correct values for things like the number of columns and rows.

My immediate goal is to identify which pixels contain values that meet a particular criterion.

When I query the contents of specific pixels, it seems as though the signed 32 bit integer is being converted into a 24 bit value that is returned as an RGB triplet. This is trouble because I am losing information -- specifically, the small-valued (on the scale of a 31-bit integer) pixels are returned to me as (0,0,0). Indeed, the only non-zero valued pixels when read this way are the handful of pixels from the detector that were malfunctioning.

Here is the essence of what I have tried so far:

Code: Select all

use Image::Magick;
my $p = Image::Magick->new();
print $p->Get('columns'), $/;              # correctly returns the width of the image
print $p->Get('pixel[170,88]'), $/;        # returns (0,0,0,0), I am expecting a signed 32 bit number evaluating to 19
print $p->Get('pixel[258,91]'), $/;        # returns (16,16,16,0), I am expecting 1048575 = 2^20-1 = a value indicating a broken pixel
After spending a few hours with the PerlMagick documentation, I am unclear on how to obtain the signed 32 bit number from a pixel. I would be grateful for a suggestion.

Here is an example of one of my images: ... xample.tif

Thank you in advance,

Re: Tiff file with signed 32-bit samples

Posted: 2011-12-19T13:18:57-07:00
by magick
Pixel values are converted to fit in the range supported by ImageMagick when ImageMagick is compiled. You likely have the Q16, or 16-bits-per-pixel, version of ImageMagick. You can rebuild ImageMagick either with HDRI support (floating point) or Q32 which supports 32-bit unsigned.

The current release of ImageMagick uses 4 channels (RGBA) even if the image is 1 channel. The new version of ImageMagick, 7.0.0, supports variable channels. If your image only has one channel, ImageMagick will only store one channel internally. Unfortunately it may be 6 more months before ImageMagick 7.0.0 is available for beta testing.

Re: Tiff file with signed 32-bit samples

Posted: 2011-12-19T13:45:05-07:00
by BruceRavel
Brilliant! I recompiled with

Code: Select all

and now I can make progress. Thanks a million.