Remove outside lines from the image

조회 수: 19 (최근 30일)
Chathurika Sandamali
Chathurika Sandamali 2021년 3월 24일
댓글: Chathurika Sandamali 2021년 3월 27일
I use hough function for line detection. but lines on the outside of the image are also detected.
%Edge detection
BW1 = edge(wiener,'sobel');
%Hough Function
BW1 = imrotate(BW1,0,'crop');
figure, imshow(BW1);
[H,theta,rho] = hough(BW1);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot)
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(BW1,theta,rho,P,'FillGap',5,'MinLength',10);
figure, imshow(BW1), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
%assign values to arrays
arr1Yx(:,k) = xy(1,1);
arr2Yy(:,k) = xy(1,2);
arr3Rx(:,k) = xy(2,1);
arr4Ry(:,k) = xy(2,2);
%Separate line1 and line2 array
if xy(1,1) > value
line1(:,k) = xy(1,1);
line1Y(:,k) = xy(1,2);
value = xy(1,1);
elseif xy(1,1) < value
fprintf('Line 2 - %d - %d\n', startline2, value);
line2(:,k) = xy(1,1);
line2Y(:,k) = xy(1,2);
end
end

채택된 답변

Matt J
Matt J 2021년 3월 24일
편집: Matt J 2021년 3월 24일
Can't you just pre-delete the edge values?
BW1([1:10,end-9:end], [1:10,end-9:end]) = 0;
  댓글 수: 1
Chathurika Sandamali
Chathurika Sandamali 2021년 3월 27일
imclearborder() function is worked. Thank you.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by