使用 LibTIFF C++ 写入 10,12 位 TIFF 文件
我正在尝试使用 LibTIFF 编写 10,12 位 RGB TIFF 文件。
像素数据本地保存在无符号短缓冲区(16 位)中
1) 如果我将 TIFFTAG_BITSPERSAMPLE 设置为 10 或 12,则不会从缓冲区读取足够的位,并且输出不正确。 (我知道它只是读取每个组件 10 或 12 位,而不是 16 位,这就是问题所在)
2)我尝试将这些位打包到缓冲区中,这样它实际上是 12-R、12-G、12- B.在这种情况下,我认为文件写入正确,但我找不到的查看器可以正确显示该图像。
3)如果我将TIFFTAG_BITSPERSAMPLE
设置为16,观众可以显示TIFF图像,但是我有一个问题,我不知道图像最初是10位还是12位(如果我想稍后使用 LibTIFF 阅读)。此外,观看者期望动态范围为 16 位,而不是 10 或 12 位,这也会导致观看效果不佳。
4) 最烦人的部分是我无法在网络上找到一张 10、12 或 14 位 TIFF 图像来查看标题应该是什么样子。
最后,将 10 位或 12 位图像数据写入 TIFF 文件的正确方法是什么?
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 ?????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TIFF 规范没有指定存储 10、12 或 14 的方式图像中每个通道的位数。根据编码器和解码器的不同,仍然可以处理此类图像,但这实际上是一个实现细节,因为它们不需要这样做。
如果您希望 TIFF 的精度超过 8 位,则唯一的选择是 16 位(或浮点数,但这是一个不同的故事)。
我不知道有任何图像格式对这些位深度有特定的支持,因此如果您必须以特定的位深度存储图像,那么查看器可能会成为问题。我能想到的最简单的解决方法是将每个像素存储为 16 位,并将原始位深度作为元数据(例如在 ImageDescription 标签中),但这完全取决于图像的用途以及为什么需要此信息。
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.
您可以将图像存储为多图像文件。例如,对于 12 位源,一幅图像将是使用高 8 位和第二个 16 位灰度(低 4 位和 4 位填充的组合)的 RGB(8) 图像。这使得 TIFF 可以在带有标准程序的显示器上查看,并且可以使用自定义软件检索额外的精度。
我不同意“异国情调”的位深度不好。此格式会将图像大小减小 5/6。您甚至可以将第二张图像存储为重新缩放版本,该版本将 4 位紧密打包,无需填充即可缩小 3/4 尺寸。对于非常大的数据集,由于数据的性质而无法选择压缩,这种节省可能非常显着。即,许多科学和机器视觉应用可能需要未掺杂的位。从多图像 tiff 转换为 16 位 tiff 的能力将允许使用标准程序和图像库。
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.