how to read numbers of images and save the change

2 views (last 30 days)
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

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 6 Jul 2019
Edited: KALYAN ACHARJYA on 6 Jul 2019
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
  4 Comments
Image Analyst
Image Analyst on 7 Jul 2019
[~, baseFileNameNoExt, ext] = fileparts(Images(i).name)
outputFileName = fullfile(outDirectory, [baseFileNameNoExt, '.PNG'])
imwrite(result1, outputFileName);

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!