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

97 ビュー (過去 30 日間)
Megan Clapperton
Megan Clapperton 2018 年 6 月 1 日
回答済み: yanqi liu 2021 年 11 月 22 日
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 件のコメント
Michael Nothem
Michael Nothem 2018 年 8 月 6 日
Did you get it figured out? I am trying to do the same thing!

サインインしてコメントする。

回答 (2 件)

Rafael S.T. Vieira
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
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"

サインインしてコメントする。


yanqi liu
yanqi liu 2021 年 11 月 22 日
sir,may be use smooth3、isosurface to generate 3D data,such as

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by