AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
January 2012

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2012.01.04 10:54 "reading rgb values from 16 bits tif images", by Martin Alegre
2012.01.04 12:37 "Re: reading rgb values from 16 bits tif images", by <mikk@go2.pl>
2012.01.04 14:07 "Re: reading rgb values from 16 bits tif images", by Olivier Paquet
2012.01.04 14:55 "Re: reading rgb values from 16 bits tif images", by Martin Alegre
2012.01.04 15:08 "Re: reading rgb values from 16 bits tif images", by Olivier Paquet
2012.01.04 14:42 "Re: reading rgb values from 16 bits tif images", by Bob Friesenhahn
2012.01.04 15:02 "Re: reading rgb values from 16 bits tif images", by Martin Alegre
2012.01.04 15:24 "Re: reading rgb values from 16 bits tif images", by Bob Friesenhahn
2012.01.05 09:12 "Re: reading rgb values from 16 bits tif images", by Martin Alegre

2012.01.04 10:54 "reading rgb values from 16 bits tif images", by Martin Alegre

Dear all,

I'm trying to read the RGB values of 16 bits tif images. To do that, I'm
using the TIFFReadRGBAImage function to first load the data into memory and
store it into a buffer. Then, by calling the TIFFGet{R,G,B} functions, I
read each of the pixel values at the different channels. Although, the data
seemed to be loaded in memory correctly, when I compared the pixel values
obtained using LibTiff with those obtained in Matlab, the pixel values
don't match each other. Besides that, I've the impression that the pixel
values obtained using LibTiff span up to 2^8 and not to 2^16. Any
suggestions on what I'm doing wrong? Below, I'm adding the code snippet for
illustration purposes. Any comments/lights are really welcomed :-)
Besides that, does the LibTiff library supports now 32-bits images?

TIFF* tif = TIFFOpen("example16bits.tif", "r");
if (tif) {
        uint32 imageWidth, imageLength;
        uint16 bps;

        TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imageWidth);
        TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imageLength);
        TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);

        uint32 npixels = imageWidth * imageLength;
        uint32* raster = NULL;

        raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));

        if (raster != NULL) {

            if (! TIFFReadRGBAImage(tif, imageWidth, imageLength, raster,
0)) {
                std::cerr << "Could not read image!" << std::endl;
                return (EXIT_FAILURE);
            }

            d = 0;
            for(e = imageLength - 1; e != -1; e--){
                for(c = 0; c < imageWidth; c++){
                    pixel = e * imageWidth + c;

                    uint16 red    =
static_cast<uint16>(TIFFGetR(raster[pixel]));
                    uint16 green =
static_cast<uint16>(TIFFGetG(raster[pixel]));
                    uint16 blue   =
static_cast<uint16>(TIFFGetB(raster[pixel]));

                    std::cout << red << " " << green << " " << blue <<
std::endl;
                }
              }

            _TIFFfree(raster);
        }

        TIFFClose(tif);
}

Best,

Tin