我发现通过imread函数导入大型multi-tiff文件对于我需要做的事情来说很慢。我使用googlefoo并找到tutorial来解释加载tif文件的更快方法。我试图使用代码(下面),但它一直在崩溃。正如教程所述,可能必须根据我尝试加载的内容更改代码,这就是我被困住的地方。我不太了解tifflib尝试更改代码。
是否有人能够帮助解释代码,以便我知道从哪里开始处理数据。
InfoImage=imfinfo('file.tif');
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
NumberImages=length(InfoImage);
FinalImage=zeros(nImage,mImage,NumberImages,'uint16');
FileID = tifflib('open',loaderpath,'r');
rps = tifflib('getField',FileID,Tiff.TagID.RowsPerStrip);
for i=1:NumberImages
tifflib('setDirectory',FileID,i);
% Go through each strip of data.
rps = min(rps,nImage);
for r = 1:nImage
row_inds = r:min(nImage,r+rps-1);
stripNum = tifflib('computeStrip',FileID,r);
FinalImage(row_inds,:,i) = tifflib('readEncodedStrip',FileID,stripNum);
end
end
tifflib('close',FileID);
Tiff文件格式
Filename 'img_stack.tif'
FileModDate '25-Oct-2017 09:31:40'
FileSize 49960190
Format 'tif'
FormatVersion []
Width 1280
Height 720
BitDepth 8
ColorType 'grayscale'
FormatSignature [73,73,42,0]
ByteOrder 'little-endian'
NewSubFileType 0
BitsPerSample 8
Compression 'PackBits'
PhotometricInterpretation 'BlackIsZero'
StripOffsets 1x66 double
SamplesPerPixel 1
RowsPerStrip 11
StripByteCounts 1x66 double
XResolution 72
YResolution 72
ResolutionUnit 'Inch'
Colormap []
PlanarConfiguration 'Chunky'
TileWidth []
TileLength []
TileOffsets []
TileByteCounts []
Orientation 1
FillOrder 1
GrayResponseUnit 0.0100000000000000
MaxSampleValue 255
MinSampleValue 0
Thresholding 1
Offset 19840