我正在尝试读取TIFF图像来执行处理。理想的做法是能够在OpenCV结构中导入这个图像,但即使以不同的方式访问它也会很好。访问TIFF图像
如果我在图像上运行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("%f\n", buf[col]);
printf("\n");
}
printf("ScanLineSize: %d\n",scanline);
_TIFFfree(buf);
TIFFClose(tif);
}
}
我
GCC test.c的-ltiff -o测试编译
当我运行它,我得到
test.c: In function ‘main’:
test.c:24: warning: dereferencing ‘void *’ pointer
test.c:24: error: invalid use of void expression
任何提示?谢谢你的时间。
也许你应该张贴你的源代码,否则我们无法给你的提示就可以了,对不对? ;) – Constantinius
我添加了一些代码,我尝试过,我发现在线。 tsize_t是一个指向void的指针,我试图使这个代码工作,但我无法。 – Danilo
我现在查看了tiff教程,但在代码中找不到任何错误。什么是你的第24行,编译器指出错误? – Constantinius