How do I Cut the black edge of the image automatically
조회 수: 10 (최근 30일)
이전 댓글 표시
As title, how do I make the edge cutting by masking automatically(about 300 pictures)?
I make one edge cutting as the example
thanks!
댓글 수: 0
채택된 답변
DGM
2022년 12월 20일
This is one way to automatically crop off nominally-solid color borders.
% read the image, create a grayscale copy
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1236847/raw_picture.jpg');
testpict = im2double(rgb2gray(inpict));
% find the central region by looking at the
% variance along row/column vectors
% nonzero threshold allows for noise in BG
th = 0.005;
varx = var(testpict,0,1)>th;
vary = var(testpict,0,2)>th;
% extract the central region
xrange = find(varx,1,'first'):find(varx,1,'last');
yrange = find(vary,1,'first'):find(vary,1,'last');
outpict = inpict(yrange,xrange,:);
imshow(outpict)
For processing multiple images, there are a number of examples around. This is a good starting point.
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!