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

35 visualizzazioni (ultimi 30 giorni)
Megan Clapperton
Megan Clapperton il 1 Giu 2018
Risposto: yanqi liu il 22 Nov 2021
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

Risposte (2)

Rafael S.T. Vieira
Rafael S.T. Vieira il 1 Giu 2020
Modificato: Rafael S.T. Vieira il 6 Ago 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 Commento
r r
r r il 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"

Accedi per commentare.


yanqi liu
yanqi liu il 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