Hi all,I want to enlarge the white border of a picture (not crop the white border, mind you), what command or code should I use?

1 次查看(过去 30 天)
Note in this image that the symbol 'Y' is clearly cut off a little and the distance between it and the edge is clearly not the same as the distance between the symbol 'X' and the edge.
Is there any way to freely adjust the white border? And next I need to keep adjusting the position of the symbols 'X' and 'Y'.
Thanks in advance!

回答(1 个)

Divyam
Divyam 2024-9-11
The "padarray" function can be utilized to pad the image array such that the white border of the picture is enlarged.
% Read the image
img = imread('defaultImage.png');
% Define the padding size for padding on the left side
leftPadding = 30;
% Define the padding color (white)
paddingColor = 255;
% Setting the direction of padding as "pre" to add horizontal padding to the left side
paddedImg = padarray(img, [0, leftPadding], paddingColor, 'pre');
% Optionally, save the padded image
imwrite(paddedImg, 'paddedImage.jpg');
% Displaying the original and padded images
figure;
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(paddedImg);
title('Image with Enlarged White Border');
For more information regarding the "padarray" function, refer to this documentation: https://www.mathworks.com/help/images/ref/padarray.html

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by