Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 32位TIFF图像显示为白色,与原始图像不同_C_Tiff_Imagej_Libtiff - Fatal编程技术网

C 32位TIFF图像显示为白色,与原始图像不同

C 32位TIFF图像显示为白色,与原始图像不同,c,tiff,imagej,libtiff,C,Tiff,Imagej,Libtiff,我在使用LibTIFF库保存图像时遇到问题 在我的代码中,我有一个表示图像像素值的浮点数组。当我将这些值保存到原始文件时,它看起来很好。但是,当我尝试使用LibTIFF库将其保存为TIFF文件时,在ImageJ中打开它时,图像看起来非常好,但是在Photoshop或Windows中打开它时,它看起来很奇怪(请看下面),Gimp显示了一个完全透明的图像(好像图像中根本没有数据) 我使用ImageJ打开原始文件,将图像类型设置为32位实数,并勾选小尾端字节顺序 以下是我用来保存TIFF图像的代码:

我在使用LibTIFF库保存图像时遇到问题

在我的代码中,我有一个表示图像像素值的浮点数组。当我将这些值保存到原始文件时,它看起来很好。但是,当我尝试使用LibTIFF库将其保存为TIFF文件时,在ImageJ中打开它时,图像看起来非常好,但是在Photoshop或Windows中打开它时,它看起来很奇怪(请看下面),Gimp显示了一个完全透明的图像(好像图像中根本没有数据)

我使用ImageJ打开原始文件,将图像类型设置为32位实数,并勾选小尾端字节顺序

以下是我用来保存TIFF图像的代码:

TIFF *tif= TIFFOpen(name, "w");

TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, 1);
TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 32);
TIFFSetField (tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

tsize_t strip_size = TIFFStripSize (tif);
tstrip_t strips_num = TIFFNumberOfStrips (tif); 

float* strip_buf=(float*)_TIFFmalloc(strip_size);
for (unsigned int s=0; s<strips_num; s++) {
    for (unsigned int col=0; col<width; col++) {
        strip_buf[col]=image[s][col];
    }
    TIFFWriteEncodedStrip (tif, s, strip_buf, strip_size);

}
_TIFFfree(strip_buf);
TIFFClose(tif);
TIFF*tif=TIFFOpen(名称,“w”);
TIFF设置字段(tif,TIFF标记_图像宽度,宽度);
TIFF设置字段(tif、TIFF标记_图像长度、高度);
TIFFSetField(tif、TIFFTAG_平面配置、平面配置_CONTIG);
TIFFSetField(tif,TIFFTAG_采样每像素,1);
TIFFSetField(tif,TIFFTAG_ROWSPERSTRIP,1);
TIFFSetField(tif、TIFFTAG_压缩、压缩_无);
TIFFSetField(tif、TIFFTAG_光度计、光度计_黑色);
TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,32);
TIFF设置字段(tif、TIFF标记方向、方向左上角);
tsize_t strip_size=TIFF StripSize(tif);
tstrip_t strips_num=TIFFNumberOfStrips(tif);
浮动*条带尺寸=(浮动*)\u条带尺寸;

对于(unsigned int s=0;s我怀疑您保存它的方式有问题-只是Windows Image Viewer无法正确处理32位的TIFF。由于不了解LibTIFF,我假设您可以通过将代码中的相应行调整为
8
而不是
来更改创建的TIFF的位深32
,所以它是这样写的:

TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 8);
但是,请注意,如果原始数据的强度值超过了8位所能表示的强度值,这将导致信息丢失。我不知道LibTIFF是如何进行缩放的


但仅仅因为Windows/Gimp/Photoshop没有正确显示它们并不意味着TIFF文件已损坏。

您可能需要添加以下行以指示图像是浮动32位的

    TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);

然后,您应该不会对能够读取浮动图像的程序有任何问题。

查看屏幕截图中的正确图片,我猜这只是32位TIFF文件中较低的8位。因此,当Windows image Viewer遇到它只能部分理解的内容时,可能就是这样做的;)你救了我!公共标签libtiff教程中没有这样有价值的提示。