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

1 回表示 (過去 30 日間)
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');

採用された回答

Walter Roberson
Walter Roberson 2024 年 4 月 22 日
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 件のコメント
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad 2024 年 4 月 22 日
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 2024 年 4 月 22 日
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'));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by