Libtiff:如何获取像素值或如何将 TIFF 文件转换为文本文件
我正在尝试使用 TIFFReadScanline(tif, buf, row) 方法让 libtiff 读出由一条约 500x500 32 位像素组成的 tiff 文件。这给了我 tdata_t (??) 行。
如何将此缓冲区写为文本文件或访问像素值(应该是双精度)?
我的代码如下所示:
TIFF* tif = TIFFOpen(c_str2, "r");
uint32 imagelength;
tdata_t buf;
uint32 row;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
buf = _TIFFmalloc(TIFFScanlineSize(tif));
for (row = 0; row < imagelength; row++){
TIFFReadScanline(tif, buf, row);
myfile << buf << endl;
}
在最后一行中,我尝试将整个缓冲区写入文本文件,但没有双精度值,而是十六进制值。当我用 char 缓冲区替换 tdata_t 缓冲区时,出现 ASCII 符号乱码。我想我应该将 tdata_t 缓冲区转换为双精度或字符缓冲区,但是如何转换?
它不应该是字节顺序的,因为我认为 libtiff 会自动处理这个问题。
欢迎任何建议!感谢您的帮助,祝大家周末愉快!
I'm trying to get libtiff to read out tiff files that consist of one strip of about 500x500 32-Bit pixels using the method TIFFReadScanline(tif, buf, row). This gives me tdata_t (??) rows.
How can I write out this buffer as text file or access pixel values (should be doubles)?
My code looks like this:
TIFF* tif = TIFFOpen(c_str2, "r");
uint32 imagelength;
tdata_t buf;
uint32 row;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
buf = _TIFFmalloc(TIFFScanlineSize(tif));
for (row = 0; row < imagelength; row++){
TIFFReadScanline(tif, buf, row);
myfile << buf << endl;
}
In the last line I try to write write out the whole buffer into a text file, but there are no double values but Hex-Values. When I replace the tdata_t buffer by a char buffer there is ASCII symbol gibberish. I think I should convert the tdata_t buffer to a double or char buffer but how?
It shouldn't be byte-order since libtiff handles this automatically I think.
Any suggestions welcome! Thanks for helping, wish you all a nice weekend!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<<注意到您正在输出 tdata_t 类型,这些类型可能是整数,并将它们放入十六进制以便更容易阅读。
只需循环遍历一行中的所有元素(在 buf 中)并将它们输出为带有 << 的浮点数(浮点数)buf[元素]
The << noticed you are outputting types of tdata_t which are probably ints and puts them into hex to make them easier to read.
Just loop over all the elements in a row (in buf) and output them as floats with << (float)buf[element]