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 Ansicht (letzte 30 Tage)
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!

Antworten (1)

Divyam
Divyam am 11 Sep. 2024
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

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by