
Thread
2012.11.22 12:50 "Re: [Tiff] TIFF 16 bit grayscale images", by Bharat Singh
Hi John,
Thanks a lot John :), after adding TIFFSetField (img, TIFFTAG_ROWSPERSTRIP, 16); I did not get that message and outputs are as I expected
On Thu, Nov 22, 2012 at 5:01 PM, <jcupitt@gmail.com> wrote:
Your code looks fine, the bug must somewhere else. I would set ROWSPERSTRIP, otherwise the whole file will be in a single big lump (I think).
Here's a complete example. This should work for you too.
----
/* compile with
*
* gcc -g try189.c -l tiff
*/#include <tiffio.h>
#define SIZE_X (100)
#define SIZE_Y (100)unsigned short buffer[SIZE_X * SIZE_Y];
int
main (int argc, char **argv)
{
TIFF *img;
int i;if (!(img = TIFFOpen (argv[1], "w")))
return -1;for (i = 0; i < SIZE_X * SIZE_Y; i++)
buffer[i] = i;TIFFSetField (img, TIFFTAG_IMAGEWIDTH, SIZE_X);
TIFFSetField (img, TIFFTAG_IMAGELENGTH, SIZE_Y);
TIFFSetField (img, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (img, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField (img, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField (img, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField (img, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (img, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField (img, TIFFTAG_ROWSPERSTRIP, 16);for (i = 0; i < SIZE_Y; i++)
{
if (TIFFWriteScanline (img, buffer + i * SIZE_X, i, 0) < 0)
return -1;
}TIFFClose (img);
return 0;
}
---On 22 November 2012 11:11, Bharat Singh <bharatsingh430@gmail.com> wrote:
I am trying to write 16bit grayscale images, however when I open the image,
the viewer says, Offset + image size > file length (image viewer if fiji),
there is no error when I write the imageHere is my code snippet
TIFF* img = TIFFOpen(location, "w");
TIFFSetField(img, TIFFTAG_IMAGEWIDTH, size_x);TIFFSetField(img, TIFFTAG_IMAGELENGTH, size_y); TIFFSetField(img, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(img, TIFFTAG_BITSPERSAMPLE, 16); TIFFSetField(img, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(img, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); TIFFSetField(img, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(img, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
for (int i = 0; i < size_y; i++) {
TIFFWriteScanline(img, buffer + i*size_x, i, 0);
}
TIFFClose(img);matlab I can open the image but, it is a random output which doesn't make
any sense. It would be of great help if some one could tell me if there is
a bug in this code. Also while compiling I have this warning, defaultlib
'LIBCMT' conflicts with use of other libs;IDE - visual studio 2008, OS - windows 7
--
Bharat Singh
5th year, Dual Degree Programme
Computer Science and Engineering
IIT Madras, India