Reducing the size of images by a loop

조회 수: 9 (최근 30일)
Joydeb Saha
Joydeb Saha 2021년 9월 8일
댓글: Image Analyst 2021년 9월 8일
Here I reduced the size of an image. But I want to reduce the size of all the images of my folder. Images are : abc_20190304_0001 to abc_20190304_0095. How can I make the loop?
I=imread('abc_20190304_0001.png');
imshow abc_20190304_0001.png
L = imresize(I,.25,'bilinear');
figure, imshow(L);

채택된 답변

KSSV
KSSV 2021년 9월 8일
imgNames = dir('*.png') ; % give your exntenion of images in the folder
N = length(imgNames) ; % toal number of images
% loop for each image
for i = 1:N
thisImg = imgNames(i).name ;
I=imread(thisImg);
figure(1)
imshow(I) ;
L = imresize(I,.25,'bilinear');
figure(2)
imshow(L);
end
  댓글 수: 7
Joydeb Saha
Joydeb Saha 2021년 9월 8일
Can you just make me understand the last two lines...
consider my path name is : E:\MW\Channel
and I want to save it in the same folder as : abc_20190304_0001, abc_20190304_0002 ....abc_20190304_0095 etc
Image Analyst
Image Analyst 2021년 9월 8일
You can use sprintf()
baseFileName = sprintf('%4.4d.png', i); % 0001.png for example.
fullOutputFileName = fullfile(outputFolder, baseFileName);
imwrite(L, fullOutputFileName);

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

추가 답변 (1개)

Joydeb Saha
Joydeb Saha 2021년 9월 8일
well the problem is solved

카테고리

Help CenterFile Exchange에서 Display Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by