Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing 10,12 bit TIFF files with LibTIFF C++

Tags:

c++

tiff

libtiff

I'm trying to write 10,12 bit RGB TIFF files with LibTIFF.

The pixel data is saved locally in an unsigned short buffer (16bits)

1) If I set TIFFTAG_BITSPERSAMPLE to 10 or 12, not enough bits are being read from the buffer, and the output is incorrect. (I understand that it is just reading 10 or 12 bits per component, instead of 16 and this is the problem)

2) I tried packing the bits in the buffer, so that it is really 12-R, 12-G, 12-B. In this case, I think the file is being written correctly but no viewer I could find could display this image properly.

3) If I set TIFFTAG_BITSPERSAMPLE to 16, viewers can display the TIFF image, but then I have a problem that I don't know if the image was originally 10 or 12 bits (If I want to later read it with LibTIFF). Also, the viewer expects the dynamic range to be 16 bits and not 10 or 12, also resulting in a bad view.

4) The most annoying part is that I couldn't find one 10, 12, or 14 bit TIFF image on the web to see what the header is supposed to look like.

So finally, what is the proper way to write 10 or 12 bit Image data to a TIFF file ?????

like image 654
Itsik Avatar asked Aug 15 '11 17:08

Itsik


People also ask

How do I scale a TIFF file?

Resize TIFF image by manually setting the width and height in pixels or just dragging the resize handler to resize a TIFF image. You can also lock the aspect ratio and select a preset resolution to quickly resize a TIFF image.

What is the maximum size of TIFF file?

What is the maximum size of a TIFF file? The format uses 32bit offsets, and as such, it is limited to 4 gigabytes. Many implementations handle these offsets using signed integers, and thus support files of up to 2 gigabytes, but the only real limit resulting from the format specification is 4 gigabytes.

What is long form of TIFF file format which compression standard for images?

TIFF. Tagged Image File Format (TIFF) has a TIFF or TIF extension. It creates very large image size as it contains a large volume of image data (TIFF stores its storage algorithm as a part of the image file). TIFF images are usually saved using 24-bit or 48-bit (in the last case each RGB color store 16 bit alone).


2 Answers

The TIFF specification does not specify a way to store 10, 12 or 14 bits per channel in an image. Depending on the encoder and decoder, it may still be possible to work with such images, but it is effectively an implementation detail, as they are not required to do this.

If you want more than 8 bits of precision in a TIFF, your only choice is 16 (or floating point, but that's a different story).

I'm not aware of any image format with specific support for these bitdepths, so viewers will likely be a problem anyway if you must store the image with that specific bitdepth. The simplest workaround I can think of would be to just store as 16 bits per pixel and put the original bitdepth as metadata (e.g. in an ImageDescription tag), but it all depends on what the images will be used for and why you need this information.

like image 123
Michael Madsen Avatar answered Sep 18 '22 01:09

Michael Madsen


You can store the image as a multi-image file. For example, with a 12 bit source, one image would be an RGB(8) image using the upper 8 bits and a second 16bit gray scale that was a combination of the low four bits and four bits of padding. This gives a TIFF that can be viewed with on a monitor with standard programs and the extra precision can be retrieved with custom software.

I disagree that 'exotic' bit depths are not good. This format would reduce the image size by 5/6. You could even just store the 2nd image as a re-scaled version that would have the 4 bits tightly packed without padding for a 3/4 size reduction. This savings can be significant with very large data sets, where compression is not an option due to the nature of the data. Ie, many scientific and machine vision applications may want the un-adultered bits. The ability to convert from the multi-image tiff to a 16-bit tiff would allow the use of standard programs and image libraries.

like image 25
artless noise Avatar answered Sep 17 '22 01:09

artless noise