Hi Dayeon,
I have implemented the code based on your request. It rescales an image by a specified ratio, centers the original image within the rescaled image, and visually compares the original and rescaled images for analysis or visualization purposes. Here is the example code snippet,
% Read the original image
originalImage = imread('/MATLAB Drive/IMG_7116.JPG');
% Define the rescale ratio (e.g., 2 for doubling the size)
rescaleRatio = 2;
% Calculate the new dimensions based on the rescale ratio
newHeight = round(size(originalImage, 1) * rescaleRatio);
newWidth = round(size(originalImage, 2) * rescaleRatio);
% Create a new blank image with the new dimensions
rescaledImage = uint8(zeros(newHeight, newWidth, size(originalImage, 3)));
% Calculate the center of the rescaled image
centerX = round(newWidth / 2);
centerY = round(newHeight / 2);
% Calculate the starting and ending points for copying the original image to the center of the rescaled image
startX = max(1, round(centerX - size(originalImage, 2) / 2));
endX = min(newWidth, startX + size(originalImage, 2) - 1);
startY = max(1, round(centerY - size(originalImage, 1) / 2));
endY = min(newHeight, startY + size(originalImage, 1) - 1);
% Copy the original image to the center of the rescaled image
rescaledImage(startY:endY, startX:endX, :) = originalImage;
% Display the original and rescaled images
figure;
subplot(1, 2, 1);
imshow(originalImage);
title('Original Image');
subplot(1, 2, 2);
imshow(rescaledImage);
title('Rescaled Image with Center Standard');
Please see attached.
Feel free to modify the code based on your preferences. I hope this answers your question.