Splitting and Saving multiple images

2 views (last 30 days)
Eberechi ICHI
Eberechi ICHI on 24 Mar 2021
Edited: Jan on 24 Mar 2021
Hello,
Please i am trying to save multile images generated by the code.
I want the number of the image to start from 1 but its starting from 16.
Can someone out there please help.
new_I=imresize(I,[381,3041]);
S=190;
m=2;
n=16;
for j = 1:m
for i = 1:n
row1 = (j-1)*S+1 ;
row2 = row1 + S ;
col1 = (i-1)*S+1 ;
col2 = col1+S;
PR_NB = new_I (row1:row2 , col1:col2, :);
base_name = sprintf('%s_%i.jpg',char(org_name(end)),n);
full_name = fullfile (newfol, base_name);
fprintf('Saving %s\n', char(full_name));
imwrite( PR_NB, char(full_name)) ;
n=(n+1)
end
end
Thanks

Accepted Answer

Jan
Jan on 24 Mar 2021
Edited: Jan on 24 Mar 2021
Then do not use n as counter, but another one:
iFile = 1;
...
base_name = sprintf('%s_%i.jpg', org_name{end}, iFile);
full_name = fullfile(newfol, base_name);
imwrite( PR_NB, full_name) ;
iFile = iFile + 1;
By the way, you can omit the "char()", because fullname is a char already.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!