How to remove frame boundary from object boundary

조회 수: 4 (최근 30일)
Syed Sameer Ul Hasan
Syed Sameer Ul Hasan 2018년 6월 4일
댓글: Syed Sameer Ul Hasan 2018년 6월 5일
How can I remove the false object boundaries detected at the frame edges ? I only need the curve part to be my boundary.
Here is my code:
clc; clear; close all;
OM = imread('002.jpg');
imshow(OM)
W = rgb2gray(OM);
imshow(W)
binaryImage=imbinarize(W);
hold on
imshow(binaryImage);
BW = bwareafilt(binaryImage,1);
[B,L,N] = bwboundaries(BW,'noholes');
imshow(BW); hold on;
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
else
plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
end
end
  댓글 수: 2
Varun Garg
Varun Garg 2018년 6월 5일
Can you attach the image for me to replicate the whole thing?
Syed Sameer Ul Hasan
Syed Sameer Ul Hasan 2018년 6월 5일

Sure. Here it is. https://drive.google.com/file/d/1hMiDy5iIeS_Xlu1JilLBMXdrx0NRow9K/view?usp=drivesdk

Which transforms to:

https://drive.google.com/file/d/1TVenArXSqDcD2JSC4Md4R40LpTNuNJxT/view?usp=drivesdk

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

답변 (1개)

KSSV
KSSV 2018년 6월 5일
If (x,y) are your boundary points......something like below should work:
[m,n] = size(I) ;
%
x(x==1) = [] ;y(x==1)= [] ;
x(x==m) = [] ;y(x==m) = [] ;
x(y==n) = [] ;y(y==n) = [] ;

Community Treasure Hunt

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

Start Hunting!

Translated by