필터 지우기
필터 지우기

Find intersection points between a line and a boundary

조회 수: 5 (최근 30일)
Ali razi
Ali razi 2020년 7월 19일
댓글: KSSV 2020년 7월 19일
I am trying to find the intersection points between a line and a boundary, how can I do it?
Code:
clc;
clear;
close all;
url='https://cdn.pixabay.com/photo/2012/04/01/17/05/brazil-23548_960_720.png';
I = imread(url);
I = rgb2gray(I);
[yDim,xDim] = size(I);
if yDim>xDim
lineLength = yDim;
else
lineLength = xDim;
end
imshow(I);
hold on;
axis on;
%Boundary
BW = imbinarize(I);
[B,L] = bwboundaries(BW,'noholes');
k=1;
stat = regionprops(I,'Centroid');
b = B{k};
c = stat(k).Centroid;
yBoundary = b(:,2);
xBoundary = b(:,1);
centroidy = c(:,2);
centroidx = c(:,1);
plot(yBoundary, xBoundary, 'g', 'linewidth', 2);
angle = 270;
xLine(1) = centroidx;
yLine(1) = centroidy;
xLine(2) = xLine(1) + lineLength * cosd(angle);
yLine(2) = yLine(1) - lineLength * sind(angle);
plot(xLine, yLine);

답변 (1개)

KSSV
KSSV 2020년 7월 19일
  댓글 수: 6
Ali razi
Ali razi 2020년 7월 19일
The first thing that popped in my mind. The results are the same. Any issue why not use rot90?
KSSV
KSSV 2020년 7월 19일
It just needs a transpose......so we transpse using '.

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

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by