Martin Alegre
2012-01-04 10:54:57 UTC
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
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