I have a set of images(jpg) in a file and I want to create a for loop to go through all of them and convert them to a gray scale images and save them into the same directory. I am using this code:
contents = dir('*.jpg') % or whatever the filename extension is
for i = 1:numel(contents) filename = contents(i).name; % Open the file specified in filename, do your processing...
[path name] = rgb2gray(filename); out_filename = sprintf('%s.jpg', name); % write jpg output to 'out_filename'
fprintf(1, 'Writing %s\n', out_filename);end
I actually want to know how I can do two things. First is gray all the images and store them into my directory, second is to add my gray images into .mat file I will appreciate your help.
Best Answer