save/write and load/read stack image files in Matlab

Write:

imageData = ones([100 100 10]);
tifFile = ‘ImageStack.tif’;
for i = 1:10
imwrite( imageData (:,:,i), tifFile,’WriteMode’,’append’);
end

Load:

tifFile = ‘ImageStack.tif’;
infoImage = imfinfo(tifFile);
w = InfoImage(1).Width;
h = InfoImage(1).Height;
planeNo = length(InfoImage);
imageData = zeros(h,w,planeNo,’uint16′);
for i = 1:planeNo
imageData(:,:,i) = imread(tifFile,’Index’,i);
end

Advertisements