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?

33 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 2 Jan 2017
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;

Sign in to comment.

Answers (4)

Image Analyst
Image Analyst on 30 Dec 2016
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 on 20 May 2018
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 on 21 May 2018
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 Comments
Image Analyst
Image Analyst on 6 Apr 2021
@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.

Sign in to comment.


hf fh
hf fh on 21 May 2018
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;

Community Treasure Hunt

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

Start Hunting!