Efficiently saving multislice tiff using Tifflib?

조회 수: 4 (최근 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 CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by