Tiff file with signed 32-bit samples

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
BruceRavel
Posts: 2
Joined: 2011-12-19T11:45:13-07:00
Authentication code: 8675308

Tiff file with signed 32-bit samples

Post by BruceRavel »

Hi,

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();
$p->Read(filename=>"image.tif");
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: http://millenia.cars.aps.anl.gov/~ravel ... xample.tif

Thank you in advance,
Bruce
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Tiff file with signed 32-bit samples

Post 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.
BruceRavel
Posts: 2
Joined: 2011-12-19T11:45:13-07:00
Authentication code: 8675308

Re: Tiff file with signed 32-bit samples

Post by BruceRavel »

Brilliant! I recompiled with

Code: Select all

--with-quantum-depth=32
and now I can make progress. Thanks a million.

B
Post Reply