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?
조회 수: 2 (최근 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!
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
