2019.12.09 20:19 "[Tiff] help writing RGB TIFF", by Paul Hemmer

2019.12.09 21:06 "Re: [Tiff] help writing RGB TIFF", by Paul Hemmer

Hi Bob,

Thanks. Yes, samples_per_pixel == 3 (sorry about that)

I'm using LibTIFF 4.0.10

tiffdump output is as follows:

C:\LibTIFF4010\tiff-4.0.10\libtiff\Release>tiffdump.exe color_test.tif

color_test.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 125001480 (0x7735f08) next 0 (0)
ImageWidth (256) SHORT (3) 1<12288>
ImageLength (257) SHORT (3) 1<6144>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<5>
Photometric (262) SHORT (3) 1<2>
FillOrder (266) SHORT (3) 1<1>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<3>
XResolution (282) RATIONAL (5) 1<20480>
YResolution (283) RATIONAL (5) 1<20480>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<3>
TileWidth (322) SHORT (3) 1<256>
TileLength (323) SHORT (3) 1<256>
TileOffsets (324) LONG (4) 1152<8 715124 2101314 3685897 5628582 7440405 9271386 11300718 13612776 15930855 18178078 20882196 23711329 26305071 29177171 32474567 35440876 38147580 41258254 44569339 47293633 50032758 53234194 56346629 ...>
TileByteCounts (325) LONG (4) 1152<12477 23504 29208 29302 29061 27993 29640 29738 30251 30852 32437 31692 32883 32804 35124 36154 33427 36297 36674 49645 57254 71269 63211 46217 ...>

________________________________

From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us> Sent: Monday, December 9, 2019 3:55 PM

To: Paul Hemmer <paulhemmer@hotmail.com>
Cc: Tiff List <tiff@lists.osgeo.org>
Subject: Re: [Tiff] help writing RGB TIFF

I'm combining two 16bit grayscale images into a single RGB image (using OpenCV) to do the combination and coloring, but using LibTIFF to save it.

If I use OpenCV's imwrite function (which uses LibTIFF internally) and open the resulting TIFF file in ImageJ, it looks correct and is treated as an RGB image (info shows isRGB=true).. That is, ImageJ does not try to present 3 separate channels.

If instead I use LibTIFF and save it (using relevant fields below, note it is a tiled-tiff), and open the image in ImageJ, it looks correct (takes longer to open) but ImageJ seems to treat it as 3 independent channels and when I look at the image info, it shows isRGB=false.

What do I have to include or change to treat this as a simple RGB image?

Is your 'samples_per_pixel' value 3?

What libtiff APIs are you using to write your file?

Can you post the output of tiffdump for your RGB file?

Bob

Thanks!

TIFFSetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, 8);

TIFFSetField(tiff_handle, TIFFTAG_COMPRESSION, COMPRESSION_NONE);

TIFFSetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);

TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);

TIFFSetField(tiff_handle, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

TIFFSetField(tiff_handle, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);

TIFFSetField(tiff_handle, TIFFTAG_TILEWIDTH, 256);

TIFFSetField(tiff_handle, TIFFTAG_TILELENGTH, 256);

TIFFSetField(tiff_handle, TIFFTAG_RESOLUTIONUNIT, 3);

TIFFSetField(tiff_handle, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);