How do I Cut the black edge of the image automatically

조회 수: 10 (최근 30일)
Bill Chen
Bill Chen 2022년 12월 20일
답변: Image Analyst 2022년 12월 21일
As title, how do I make the edge cutting by masking automatically(about 300 pictures)?
I make one edge cutting as the example
thanks!

채택된 답변

DGM
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.
  댓글 수: 2
Bill Chen
Bill Chen 2022년 12월 20일
thanks a lot! It works! Could I input a fold and output with a stored fold?
Bill Chen
Bill Chen 2022년 12월 21일
Oh! I will take a look at your example first, thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 12월 21일
To process a sequence of files, see code snippets in the FAQ:

Community Treasure Hunt

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

Start Hunting!

Translated by