(none) imager-devel
/ help / lists / applications / search /

tiff with 32 bit signed integers

From: Bruce Ravel (
Date: Mon 30 Jan 2012 - 16:20:08 GMT

  • Next message: Bruce Ravel: "Re: tiff with 32 bit signed integers"


    I have recently started using Imager for a scientific computing
    project which involves reading tiff files containing signed 32 bit
    integer samples. These files are the output of a particular X-ray
    detector and I do not have the option of changing the file format.

    Here is an example of one such file.


    Imager does a fine job importing these files. I was able to read and
    interpret the images quite well enough to solve most of my problem
    once I realized that the red value returned by the getpixel method
    contained the integer value of the pixel divided by 2**32.

    My problem is that I don't quite understand how Imager is handling
    these s32 integers. I cannot alter a pixel value in a sensible
    manner. For example:

        use Imager;
        my $image = Imager->new(file=>'s32_example.tif');

        my ($r, $g, $b, $a) = $image->getpixel(x=>86, y=>150, type=>'float')->rgba;
        print $r*2**32, $/;
        ## ==> prints a number close to 10, which is
        ## what I expect for that pixel

        $image->setpixel(x=>86, y=>150, color=>[1,0,0]);

        ($r, $g, $b, $a) = $image->getpixel(x=>86, y=>150, type=>'float')->rgba;
        print $r, $/;
        ## ==> prints 0.00392156862745098
        ## which about 1/2**8, not 1, not 1/2**32

    From playing around, it seems as though the dynamic range is 0 to
    2**8-1. If I assign a number smaller than 1 to the red value, the
    pixel is set to be 0. If I assign a value larger than 256, the pixel
    is set to 0. That is all quite sensible since Imager is advertised as
    a 24 bit image handler.

    Given that getpixel does something sensible with these s32 integers,
    is there any way that I can coerce setpixel to also do something

    Alternately, is there a way that I can do a conversion of the samples
    upon import? In practice, I don't use the entire dyanmic range of the
    detector, thus I don't use the entire dynamic range of an image with
    signed 32 bit samples. In practice, all pixels are positive and the
    only pixels with values in excess of 2**8 are the ones corresponding
    to malfunctioning pixels on the detector. So if the s32 integer were
    converted to an unsigned 8 bit integer upon import, that would work
    for me (for now, at least...).

    Thanks for your help and thanks for the excellent module,


    Bruce Ravel ------------------------------------ 19767@xyz.molar.is

    National Institute of Standards and Technology Synchrotron Methods Group at NSLS --- Beamlines U7A, X24A, X23A2 Building 535A Upton NY, 11973

    My homepage: http://xafs.org/BruceRavel EXAFS software: http://cars9.uchicago.edu/ifeffit/Demeter