MATLAB: How to read numbers of images and save the change

MATLAB

i need to read a number of images (signature) then conert them to grayscale after that apply mediam filter then binarization the images and berform the morphological operation the following code doesn't contain an error but not implemented as i need
Directory='C:\Users\XXX\Desktop\Imges';
Imgs = dir(Directory);
for j=1:length(Imgs)
thisname = Imgs(j).name;
thisfile = fullfile(Directory, thisname);
try
Img = imread(thisfile); % try to read image
Im = rgb2gray(Img);
If2 = medfilt2(Im,[3 3]);
Bim=im2bw(If2);
I = bwmorph(Bim,'thicken',Inf);
figure
imshow(I)
title(thisname);
baseFileName= thisname;
fullFileName = fullfile('C:\Users\XXX\Desktop\Imges',baseFileName);
imwrite( I,fullFileName);
catch
end
end

Best Answer

Images=dir('C:\Complete_path\hand_2101\*.png');
%.............................^^ Folder Name, where Images are there, note on png/jpg
outDirectory='C:\Complete_path\result_images\';
%.............................^^ Folder Name, where you wish to save the image
% Result images will save in the folder ^^result_images
%The result_images folder will cretes by following statement
mkdir(outDirectory);
for i=1:length(Images)
ImgName=strcat('C:\Complete_path\hand_2101\',Images(i).name);
grayImage=((imread(ImgName)));
% do operation, say result image is result1
result1=.....
imwrite(result1,strcat(outDirectory,Images(i).name));
end