How to run all the image with format jpg in folder? and save into folder?

2 visualizaciones (últimos 30 días)
Hello. Anyone know how to run a folder with thousand images instead of run one by one the image? and save into folder?
I=imread('11_285.jpg');
imshow(I)
magnificationFactor = 1.2;
J=imresize(I,magnificationFactor, 'bilinear');
imshowpair(I,J,method="montage")
imwrite(J,'11_285_rescale.jpg');

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Abr. de 2024
dinfo = dir('*.jpg');
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
magnificationFactor = 1.2;
for K = 1 : nfiles
thisfile = filenames{K};
[folder, basename, ext] = fileparts(thisfile);
outfile = fullfile(folder, basename + "_rescale" + ext);
I = imread(thisfile);
J = imresize(I, magnificationFactor, 'bilinear');
imwrite(J, outfile);
end
  5 comentarios
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad el 22 de Abr. de 2024
ok thanks sir. I get it now. But now I want to crop my image. Here's my codes:
mypath = '/home/motmot/Downloads/All data/275/Ground truth/Rescale image/';
dinfo = dir(fullfile(mypath,'*_275.jpg'));
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
for K = 1 : nfiles
thisfile = filenames{K};
[folder, basename, ext] = fileparts(thisfile);
outfile = fullfile(folder, basename + "_crop" + ext);
x_cent= 450;
y_cent= 260;
size_of_cropped_img=511;
centroide=[x_cent y_cent];
I3=imread(thisfile);
xmin=x_cent-size_of_cropped_img/2;
ymin=y_cent-size_of_cropped_img/2;
I4=imcrop(I3,[xmin ymin size_of_cropped_img size_of_cropped_img]);
imshow(I4)
imwrite(I4, outfile);
end
The image for outfile for cropping image did not save in the folder. How can I save the crop image?
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad el 22 de Abr. de 2024
OK sir. I get the idea. I forgot to put 'rescale' at back the code
from this,
dinfo = dir(fullfile(mypath,'*_275.jpg'));
into this,
dinfo = dir(fullfile(mypath,'*_275_rescale.jpg'));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by