How to make a 3D Volume out of a 2D Tiff stack?

78 views (last 30 days)
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 Comment
Michael Nothem
Michael Nothem on 6 Aug 2018
Did you get it figured out? I am trying to do the same thing!

Sign in to comment.

Answers (2)

Rafael S.T. Vieira
Rafael S.T. Vieira on 1 Jun 2020
Edited: Rafael S.T. Vieira on 6 Aug 2020
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 Comment
r r
r r on 20 Nov 2021
How do I save this stack
Thank you for the excellent method, but how do I save it to 3D "format stack"

Sign in to comment.


yanqi liu
yanqi liu on 22 Nov 2021
sir,may be use smooth3、isosurface to generate 3D data,such as

Community Treasure Hunt

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

Start Hunting!

Translated by