How to make a 3D Volume out of a 2D Tiff stack?
조회 수: 36 (최근 30일)
이전 댓글 표시
I have a data set of 242 planes with x,y pixel resolution. It was taken from a microscope, I know the depth between image planes, and am looking to turn this Tiff Stack (split into individual files due to low RAM, named Flydata0000 - Flydata0242) into a 3D volume which I can eventually get a gui to play about with the image.
I have been trying Imshow to show an image array from reading the full file (containing only the fly data).
I will include what I have done already below (note I have not tried to make it 3D yet, would like corrections on what Ive done (if any) and an idea of how to go about making the stack 3D).
clearvars;
%Setting up path
fileFolder = 'E:\MyFile\Data\Low_Res\Sequence';
filePattern = fullfile(fileFolder, '*.tif');
TiffFiles = dir(filePattern);
% not using this now (fileNames = TiffFiles.name;)
numFrames = numel(TiffFiles);
for k=1:242
fileNames = TiffFiles.name;
fullfilename=fullfile(fileFolder, fileNames);
fprintf(1, 'Now reading %s\n', fullfilename);
imageArray = imread(fullfilename);
imshow(imageArray);
drawnow;
%Alternate??
% Stack=imread(['VeryLowResFly0' num2str(k, '%03.f') '.tif']);
%Stack(:,:,k)=Stack;
%imshow(Stack)
end
댓글 수: 1
답변 (2개)
Rafael S.T. Vieira
2020년 6월 1일
편집: Rafael S.T. Vieira
2020년 8월 6일
We need to create a 3D array WxHxD for storing all images, such as stack = zeros(W,H,D). Then, in the for-loop, we should read each image: stack(:,:,k) = imread(TiffFiles(k).name). For instance:
fileFolder = 'E:\MyFile\Data\Low_Res\Sequence';
filePattern = fullfile(fileFolder, '*.tif');
all_tiff = dir(filePattern);
first_image = imread(all_tiff(1).name);
[W,H] = size(first_image);
D = numel(all_tiff);
stack = zeros(W,H,D);
stack(:,:,1) = first_image;
for i = 2:D
stack(:,:,i) = imread(all_tiff(i).name);
% uncomment next line for seeing the reading progress
% disp(string(i*100.0/D) + "%");
end
% The app volumeViewer will handle the visualization
volumeViewer(stack);
I have tried the previous code on my files, and it works. However, the app volumeViewer won't work if any dimension is a singleton.
PS: I'm assuming all tiff images have the same dimensions (WxH) and are Grayscale or BW.
댓글 수: 1
r r
2021년 11월 20일
How do I save this stack
Thank you for the excellent method, but how do I save it to 3D "format stack"
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!