MATLAB: How can I convert many images from m x n x 3 to m x n by rgb2gray

Image Processing Toolboxrgb2gray

I want to convert 50 .jped images in a folder alltogether

Best Answer

img = dir('*.jpeg') ;
N = length(img) ;
for i = 1:N
thisimg = img(i).name ;
I = imread(thisimg) ;
Ig = rgb2gray(I) ;
[dir,name,ext] = fileparts(thisimg) ;
filename = [name,'_gray','.jpeg'] ;
imwrite(Ig,filename) ;
end