Borrar filtros
Borrar filtros

Batch processing images for downsampling

2 visualizaciones (últimos 30 días)
Cemre
Cemre el 13 de Jun. de 2023
Comentada: Mathieu NOE el 14 de Jun. de 2023
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.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 13 de Jun. de 2023
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 comentarios
Cemre
Cemre el 14 de Jun. de 2023
Many thanks. Much appreciated.
Mathieu NOE
Mathieu NOE el 14 de Jun. de 2023
as always, my pleasure !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by