-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize_dataset.m
More file actions
27 lines (21 loc) · 852 Bytes
/
resize_dataset.m
File metadata and controls
27 lines (21 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function resize_dataset(input_folder, output_folder, target_size)
% This function resizes all images in a dataset to the same size.
%
% input_folder: path to original dataset
% output_folder: path to save resized images
% target_size: desired output size (e.g., [1024 1024])
% Create output folder if it doesn't exist
if ~exist(output_folder, 'dir')
mkdir(output_folder);
end
% Get list of all JPG images
imageFiles = dir(fullfile(input_folder, '*.jpg'));
for i = 1:length(imageFiles)
img = imread(fullfile(input_folder, imageFiles(i).name));
% Resize directly to the target size
resized = imresize(img, target_size);
% Save resized image
imwrite(resized, fullfile(output_folder, imageFiles(i).name));
end
disp("All images resized and saved to output folder.");
end