Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
1.1 kB
2
Indexable
Never
% Prompt the user to select an image file
[filename, pathname] = uigetfile({'*.png;*.jpg;*.jpeg;*.bmp;*.tif', 'Image Files (*.png, *.jpg, *.jpeg, *.bmp, *.tif)'});
if isequal(filename, 0)
    disp('User selected Cancel');
    return;
end

% Read the selected image
originalImage = imread(fullfile(pathname, filename));

% Check if the image is grayscale
if size(originalImage, 3) ~= 1
    error('The input image must be a grayscale image.');
end

% Ensure the image is 8-bit
if ~isa(originalImage, 'uint8')
    originalImage = uint8(originalImage);
end

% Check the size of the image
[originalHeight, originalWidth] = size(originalImage);
if originalHeight ~= 1024 || originalWidth ~= 1024
    error('The input image must be 1024 x 1024 pixels.');
end

% Subsample the image to 32 x 32 pixels
newSize = [32 32];
subsampledImage = imresize(originalImage, newSize, 'bilinear');

% Display the original and subsampled images
figure;
subplot(1, 2, 1);
imshow(originalImage);
title('Original 1024 x 1024 Image');

subplot(1, 2, 2);
imshow(subsampledImage);
title('Subsampled 32 x 32 Image');

Leave a Comment