简体   繁体   English

使用 LibTIFF C++ 写入 10,12 位 TIFF 文件

[英]Writing 10,12 bit TIFF files with LibTIFF C++

I'm trying to write 10,12 bit RGB TIFF files with LibTIFF.我正在尝试使用 LibTIFF 编写 10,12 位 RGB TIFF 文件。

The pixel data is saved locally in an unsigned short buffer (16bits)像素数据本地保存在unsigned short缓冲区(16 位)中

1) If I set TIFFTAG_BITSPERSAMPLE to 10 or 12, not enough bits are being read from the buffer, and the output is incorrect. 1) 如果我将TIFFTAG_BITSPERSAMPLE设置为 10 或 12,则从缓冲区中读取的位不足,并且 output 不正确。 (I understand that it is just reading 10 or 12 bits per component, instead of 16 and this is the problem) (我知道它只是读取每个组件 10 或 12 位,而不是 16 位,这就是问题所在)

2) I tried packing the bits in the buffer, so that it is really 12-R, 12-G, 12-B. 2) 我尝试将这些位打包在缓冲区中,使其真正为 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). 3)如果我将TIFFTAG_BITSPERSAMPLE设置为 16,查看器可以显示 TIFF 图像,但是我有一个问题,我不知道图像最初是 10 位还是 12 位(如果我想以后用 LibTIFF 读取它)。 Also, the viewer expects the dynamic range to be 16 bits and not 10 or 12, also resulting in a bad view.此外,观看者期望动态范围为 16 位,而不是 10 或 12 位,这也会导致观看效果不佳。

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. 4) 最烦人的部分是我在 web 上找不到一张 10、12 或 14 位 TIFF 图像来查看 header 应该是什么样子。

So finally, what is the proper way to write 10 or 12 bit Image data to a TIFF file?????最后,将 10 位或 12 位图像数据写入 TIFF 文件的正确方法是什么??????

The TIFF specification does not specify a way to store 10, 12 or 14 bits per channel in an image. TIFF 规范没有指定在图像中每个通道存储 10、12 或 14 位的方法。 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).如果您希望 TIFF 中的精度超过 8 位,则唯一的选择是 16(或浮点,但那是另一回事)。

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 (eg in an ImageDescription tag), but it all depends on what the images will be used for and why you need this information.我能想到的最简单的解决方法是将原始位深度存储为每像素 16 位并将原始位深度作为元数据(例如在 ImageDescription 标记中),但这完全取决于图像的用途以及您需要此信息的原因.

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.例如,对于 12 位源,一个图像将是使用高 8 位和第二个 16 位灰度的 RGB(8) 图像,后者是低四位和四位填充的组合。 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.这提供了一个可以在带有标准程序的监视器上查看的 TIFF,并且可以使用自定义软件检索额外的精度。

I disagree that 'exotic' bit depths are not good.我不同意“异国情调”的位深度不好。 This format would reduce the image size by 5/6.这种格式会将图像大小减小 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.您甚至可以将第二张图像存储为重新缩放的版本,该版本将 4 位紧密打包而无需填充以减小 3/4 大小。 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.从多图像 tiff 转换为 16 位 tiff 的能力将允许使用标准程序和图像库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM