필터 지우기
필터 지우기

Batch processing images for downsampling

조회 수: 2 (최근 30일)
Cemre
Cemre 2023년 6월 13일
댓글: Mathieu NOE 2023년 6월 14일
Hi,
I would like to perform downsampling for like over 700 images. It is pretty time-consuming to do it one by one. How can I achieve it at one time?
Thanks a lot.

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 6월 13일
hello
see example below - adapt to your own needs
%% Initalize the data
dataDir= fullfile(pwd); % select appropriate directory
exts = {'.jpg','.png','.tif'}; % choose valid file extensions like {'.jpg', '.png'}
resize_size = 100; % pixels size for output img
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions',exts,'LabelSource','foldernames');
countEachLabel(imds);
numImages = numel(imds.Files);
for i = 1:numImages
img = readimage(imds, i);
[m,n,p] = size(img);
% compute scale factor (same on both dimensions)
scale_factor = min(resize_size/m,resize_size/n);
img3= imresize(img, scale_factor);
figure(i),
img4= imshow(img3, 'InitialMagnification', 800);
drawnow;
Train{i} = (img3); %output image stored in cell
end
  댓글 수: 8
Cemre
Cemre 2023년 6월 14일
Many thanks. Much appreciated.
Mathieu NOE
Mathieu NOE 2023년 6월 14일
as always, my pleasure !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by