How to resize multiple folder images and save it in MATLAB?

조회 수: 4 (최근 30일)
Faheem Ur Rehman
Faheem Ur Rehman 2021년 7월 12일
댓글: Walter Roberson 2021년 7월 13일
I have three folder and each folder contain 10 images. I want to resize each images to 28x28 and then save 28x28 images. I want that my code automatically pick folder one by one.

답변 (1개)

Catalytic
Catalytic 2021년 7월 12일
편집: Catalytic 2021년 7월 12일
Yes, that should be easy, but you haven't told us what part of it you're having difficulty with. If I had to guess, you are struggling to automatically get a list of folders to loop over. One way is,
s=dir;
idx=~startsWith({s.name},'.') & [s.isdir];
folders={s(idx).name}
  댓글 수: 2
Faheem Ur Rehman
Faheem Ur Rehman 2021년 7월 13일
i did't get your code where you use imresize command
Walter Roberson
Walter Roberson 2021년 7월 13일
nfolders = length(folders);
for J = 1 : nfolders
thisfolder = folders(J).name;
fileinfo = dir(thisfolder);
fileinfo([fileinfo.isdir]) = []; %remove . .. and other folders
nfiles = length(fileinfo);
for K = 1 : nfiles
thisfile = fullfile(thisfolder, fileinfo(K).name);
thisimg = imread(thisfile);
thisimg28 = imresize(thisimg, 28, 28);
%you would now want to save thisimg28... but you did not say WHERE
%you want to save it
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by