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

36 visualizaciones (últimos 30 días)
Megan Clapperton
Megan Clapperton el 1 de Jun. de 2018
Respondida: yanqi liu el 22 de Nov. de 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
  1 comentario
Michael Nothem
Michael Nothem el 6 de Ag. de 2018
Did you get it figured out? I am trying to do the same thing!

Iniciar sesión para comentar.

Respuestas (2)

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

Iniciar sesión para comentar.


yanqi liu
yanqi liu el 22 de Nov. de 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