writing a sequence of images inside a for loop using matix

2 views (last 30 days)
i have sequence of images formed by processing inside a for loop. I need to write them into a new folder using the concept of matrix

Accepted Answer

Geoff Hayes
Geoff Hayes on 11 Sep 2014
Jishnu - since your code produces a new image at each iteration of the for loop, then you could do something like the following
% initialize the folder/path
folderToSaveImg = '/Users/myName/someDirectory/images';
% do your loop
for k=1:100
% do the processing to create the image named img
img = randi(255,100,100,3); % example only
% create the file name
fileName = sprintf('image%d.mat',k);
% join the file name to the folder name
fileDestination = fullfile(folderToSaveImg, fileName);
% save the image as a matrix
save(fileDestination,'img');
end
The above code (example only) will save 100 images from the sequence to individual mat files where the data stored in the file is a three dimensional matrix.
  4 Comments
Image Analyst
Image Analyst on 11 Sep 2014
Jishnu, your comment seems to indicate that you think an image and a matrix are different things. Why is that? In MATLAB, an image is a matrix, so you don't need 2 things: an image and some separate matrix. They are one and the same.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!