Efficiently saving multislice tiff using Tifflib?

49 ビュー (過去 30 日間)
Katherine
Katherine 2014 年 11 月 18 日
コメント済み: Katherine 2014 年 11 月 18 日
I am trying to use the Tiff(*.tif, 'w') function to save a tiff with multiple frames/slices. The code that I have works, but takes a while to run, especially when I try to use it on 400+ slice tiffs. I have only been able to save multislice tiffs using this rather clunky set of for loops. If I try to write the entire thing at once, I end up with a one slice tiff file that contains all of the slices overlaid on top of each other. If anyone has encountered this problem, or knows a solution I would appreciate it.
Here is the code I have:
FileTif='11_7_dimer_1E4_s1_8_20slice.tif';
InfoImage=imfinfo(FileTif);
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
NumberImages=length(InfoImage);
FinalImage=zeros(nImage,mImage,NumberImages,'uint16');
TifLink = Tiff(FileTif, 'r');
for i=1:NumberImages
TifLink.setDirectory(i);
FinalImage(:,:,i)=TifLink.read();
end
TifLink.close();
intFinalImage = int16(FinalImage);
for numin = 1:NumberImages
tiffFile = strcat('bksub_', FileTif);
for numin = 1
t = Tiff(tiffFile,'w')
tagstruct.SampleFormat = Tiff.SampleFormat.Int;
tagstruct.ImageLength = size(intFinalImage,1);
tagstruct.ImageWidth = size(intFinalImage,2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.RowsPerStrip = 16;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky
tagstruct.Software = 'MATLAB';
t.setTag(tagstruct);
t.write(intFinalImage(:,:,numin));
t.close();
end
for numin = 2:NumberImages;
t = Tiff(tiffFile, 'a');
tagstruct.SampleFormat = Tiff.SampleFormat.Int;
tagstruct.ImageLength = size(intFinalImage,1);
tagstruct.ImageWidth = size(intFinalImage,2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.RowsPerStrip = 16;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky
tagstruct.Software = 'MATLAB';
t.setTag(tagstruct);
t.write(intFinalImage(:,:,numin));
t.close();
end
end

採用された回答

Chad Greene
Chad Greene 2014 年 11 月 18 日
Does this help?
  1 件のコメント
Katherine
Katherine 2014 年 11 月 18 日
Ah, yes! Much faster! Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by