save sequence of images in a folder using matlab

1 view (last 30 days)
I want to save images into a folder. I tried a code given below
[Ilabel num] = bwlabel(If);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 83]);
figure,imshow(Ibox);
for n=1:num
[r,c] = find(Ilabel==n);
% Extract letter
n1=Iout(min(r):max(r),min(c):max(c));
% Resize letter (same size of template)
img_r=imresize(n1,[42 24]);
%figure,imshow(n1);
%Uncomment line below to see letters one by one
%imshow(img_r);pause(0.5)
imwrite(img_r,['H:\\mainproject\\codes\\images\\test0.jpg' ]);
end
But only the last letter is saved in the folder. I dont know where it made mistakes.I tried a lot but i didn't get it.please help me and thanks in advance

Accepted Answer

Image Analyst
Image Analyst on 10 Jul 2015
Change the filename then:
baseFileName = sprintf('H:\\mainproject\\codes\\images\\Letter%d.png');
fullFileName = fullfile(pwd, baseFileName); % Prepend folder
imwrite(img_r, fullFileName);
  1 Comment
Image Analyst
Image Analyst on 10 Jul 2015
By the way, you can just use the bounding box, which you already got, rather than recomputing it with find(), min(), and max(). That's just a waste of time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!