Effacer les filtres
Effacer les filtres

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?

16 vues (au cours des 30 derniers jours)
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 commentaires
Arghya  Chattaraj
Arghya Chattaraj le 2 Jan 2017
Modifié(e) : Image Analyst le 2 Jan 2017
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 le 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;

Connectez-vous pour commenter.

Réponses (4)

Image Analyst
Image Analyst le 30 Déc 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 le 20 Mai 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 le 21 Mai 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 commentaires
Dellena Kinikles
Dellena Kinikles le 6 Avr 2021
Would you mind sharing the version of code that works for greyscale? thanks!
Image Analyst
Image Analyst le 6 Avr 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.

Connectez-vous pour commenter.


hf fh
hf fh le 21 Mai 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;
  1 commentaire
Image Analyst
Image Analyst le 21 Mai 2018
Correct, if the right side is a color image, and the left side is a monochrome image, you cannot stuff a color image into a monochrome image.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by