访问TIFF图像
Access TIFF image
我正在尝试读取TIFF图像以执行处理。理想的情况是能够在OpenCV结构中导入此图像,但即使以不同的方式访问它也很棒。
如果我在图像上运行tiffinfo,我会得到
TIFF Directory at offset 0x2bb00 (178944)
Subfile Type: (0 = 0x0)
Image Width: 208 Image Length: 213
Resolution: 1, 1
Bits/Sample: 32
Sample Format: IEEE floating point
Compression Scheme: None
Photometric Interpretation: min-is-black
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 1
Rows/Strip: 1
Planar Configuration: single image plane
我想访问单像素值。该图像为灰度级,其中包含的数据范围从0.0到10372.471680。
我对LibTIFF、Magick++进行了一些尝试,但无法访问单个像素值(我试图在像素上进行循环并在屏幕上打印这些值)。
这是我尝试使用的一段代码,我从一个在线示例中得到:
#include "tiffio.h"
#include "stdio.h"
int main()
{
TIFF* tif = TIFFOpen("test.tif", "r");
if (tif) {
uint32 imagelength;
tsize_t scanline;
tdata_t buf;
uint32 row;
uint32 col;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
scanline = TIFFScanlineSize(tif);
buf = _TIFFmalloc(scanline);
for (row = 0; row < imagelength; row++)
{
int n = TIFFReadScanline(tif, buf, row, 0);
if(n==-1){
printf("Error");
return 0;
}
for (col = 0; col < scanline; col++)
printf("%fn", buf[col]);
printf("n");
}
printf("ScanLineSize: %dn",scanline);
_TIFFfree(buf);
TIFFClose(tif);
}
}
我用编译它
gcc测试。c-ltiff-o测试
当我运行它时,我得到
test.c: In function ‘main’:
test.c:24: warning: dereferencing ‘void *’ pointer
test.c:24: error: invalid use of void expression
有什么提示吗?谢谢你抽出时间。
查看函数_TIFFalloc()的文档。如果它的工作方式与标准malloc类似,它将返回一个void指针,如果第24行的buf[col]语句能够正常工作,则需要将该指针强制转换为特定类型。
您必须使用修复此问题
tdata_t *buf;
buf =(tdata_t*) _TIFFmalloc(scanline);
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- 如何在 OpenCV c++ 中压缩 TIFF 格式的图像?
- 是否可以通过每次在内存中仅保存一个平铺来处理完整的平铺 tiff 图像?
- 将 16 位单通道图像写入 Tiff
- 用c++读取tiff图像
- 带有GUI的C++程序,可使用远程放置的相机进行拍摄并读取未压缩的TIFF图像
- 将 tiff 图像转换为字符串,以作为二进制应用程序/八位字节流 (C++) 发布
- c++ 32位tiff图像保存和加载
- 我如何将TIFF图像数据传递给JUCE(不支持TIFF)
- 用于将JPEG图像转换为TIFF格式的C, c++或Objective-C代码
- 处理大型TIFF图像C++/Magick/libtiff
- 访问TIFF图像
- 读取tiff图像tesseract和leptonica
- 在内存中计算TIFF图像大小[C/ c++]