Splitting and Saving multiple images

2 visualizaciones (últimos 30 días)
Eberechi ICHI
Eberechi ICHI el 24 de Mzo. de 2021
Editada: Jan el 24 de Mzo. de 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

Respuesta aceptada

Jan
Jan el 24 de Mzo. de 2021
Editada: Jan el 24 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by