最近,我有一个问题是读取16位灰色tiff图像。这种图像的每个像素具有2个样本,每个样本具有16个比特。但是,当我在OpenCV中读取它时,它始终是8位,我不确定opencv如何在 .data 中排列2个样本。我已经尝试了 imread() 中的每个标志组合,包括CV_LOAD_IMAGE_ANYDEPTH。它仍然以8位读取图像。图像信息如下(使用MatLab读取):
FileSize: 34375411
Format: 'tif'
FormatVersion: []
Width: 5597
Height: 4051
BitDepth: 32
ColorType: 'grayscale'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [16 16]
Compression: 'LZW'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: [1×4051 double]
SamplesPerPixel: 2
RowsPerStrip: 1
StripByteCounts: [1×4051 double]
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [65535 65535]
MinSampleValue: [0 0]
Thresholding: 1
Offset: 8
Software: 'pix4dmapper'
Predictor: 'Horizontal differencing'
ExtraSamples: 0
SampleFormat: {'Unsigned integer' 'Unsigned integer'}
ModelPixelScaleTag: [0.0385 0.0385 0]
ModelTiepointTag: [0 0 0 3.0791e+05 5.9588e+06 0]
GeoKeyDirectoryTag: [1×32 double]
GeoAsciiParamsTag: 'WGS84 / UTM zone 55S|WGS 84|'
GDAL_NODATA: '-10000'
有人能告诉我如何处理这种情况吗?非常感谢。
答案 0 :(得分:1)
除非您指定CV_LOAD_IMAGE_ANYDEPTH
或类似内容,否则它会自动转换。
在官方帮助网站上查看完全相同的问题(我将无耻地复制并粘贴到此字段中)。
Mat test1(1000, 1000, CV_16U, Scalar(400));
imwrite("test.tiff", test1);
Mat test2 = imread("stam.tiff", CV_LOAD_IMAGE_ANYDEPTH);
cout << test1.depth() << " " << test2.depth() << endl;
cout << test2.at<unsigned short>(0,0) << endl;
如果这不起作用,请尝试直接使用libtiff