How to import an image sequence having 30 number of TIFF images which are saved in Matlab current directory within a folder named 'test_image'? How to make image stack from this image after importing and get maximum intensity projection from stack?

10 次查看(过去 30 天)
Hi, I am beginners in Matlab. I have a image folder named as 'test_image' containing 30 numbers of TIFF images in Matlab current directory. Now I want to import all those images and want to make image stack. After that I want to get maximum intensity procetion from the stack. If anybody give me idea, I will be grateful to him. As I am beginners, so please tell me stepwise.
Thanking you in advance.
  2 个评论
Arghya  Chattaraj
Arghya Chattaraj 2017-1-2
编辑:Image Analyst 2017-1-2
Dear all,
Happy new year 2017 to all of you.
I have run following code
% Specify the folder where the files live.
myFolder = 'C:\Program Files\MATLAB\R2013a\bin\mri';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
now output is as follows....
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0001.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0002.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0003.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0004.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0005.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0006.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0007.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0008.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0009.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0010.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0011.png
Now reading C:\Program Files\MATLAB\R2013a\bin\mri\0012.png
etc
Now how to stack all those images.
I am a beginner. So please give me some example.
Thanking you in advance.
Image Analyst
Image Analyst 2017-1-2
Assuming the files are grayscale, not color, make a 3D array inside the loop just after you read in the image with imread():
if k == 1
[rows, columns, numberOfColorChannels] = size(imageArray);
allImages = zeros(rows, columns, length(theFiles)); % Preallocate space
end
% Insert image into the proper plane
allImages(:, :, k) = imageArray;

请先登录,再进行评论。

回答(4 个)

Image Analyst
Image Analyst 2016-12-30
See code in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F You'll probably want the chunk of code that uses dir().
In the middle of the loop, use cat(3,....) to stack images.

hf fh
hf fh 2018-5-20
I used the same method and came up with the same problem ???
Unable to perform assignment because the size of the left side is 1-by-300-by-300 and the size of the right side is 300-by-300-by-3.
Error in u2 (line 33) im_3D(i,:,:) = im_2D;

hf fh
hf fh 2018-5-21
I want to convert these images into 3D volume The same method was used on gray images and the results were excellent but when using colored images the images did not come out !!! I want to extract images in size 3D format Thank you
  2 个评论
Image Analyst
Image Analyst 2021-4-6
@Dellena Kinikles, are you saying the code from the FAQ and the code I gave in my answer ( https://www.mathworks.com/matlabcentral/answers/318606-how-to-import-an-image-sequence-having-30-number-of-tiff-images-which-are-saved-in-matlab-current-di#answer_248989 ) did not work? Please share your code so we can see what you did wrong. If you don't have code, please get it from the FAQ and put the cat(3, ...) code into the middle of the loop.

请先登录,再进行评论。


hf fh
hf fh 2018-5-21
I used another method but still the same problem !!!! this method : numberOfSlices=8; image = zeros(773,896, numberOfSlices); for slice = 1 : numberOfSlices files = dir('/Users/mac/Desktop/fiel2/*.tif'); dir_name='/Users/mac/Desktop/fiel2/333/'; fullFileName = fullfile('C:/Users/mac/Desktop/fiel2/333',num2str(slice),'.tif'); thisSlice = double(imread(strcat(dir_name,num2str(slice),'.tif')))/255; image(:,:,slice) = thisSlice; end view(3);
result !!!!
Unable to perform assignment because the size of the left side is 773-by-896 and the size of the right side is 773-by-896-by-3.
Error in d (line 8) image(:,:,slice) = thisSlice;

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by