0
基於Subset a region from boundary coordinates - Matlab的問題,我嘗試使用正確的,而不是(但限制爲沒有角度的矩形)。子集從邊界座標使用正確的區域 - Matlab
不過,我有輸出問題,因爲我沒有得到任何x,y座標。爲什麼?
腳本:
clc;
clear;
I = imread('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Astroid_created_with_Elipses_with_a_plus_b_const.svg/330px-Astroid_created_with_Elipses_with_a_plus_b_const.svg.png');
I = rgb2gray(I);
I = imcomplement(I);
level = graythresh(I);
BW = im2bw(I,level);
BW_filled = imfill(BW,'holes');
boundaries = bwboundaries(BW_filled);
figure,imshow(I) ;
hold on;
b = boundaries{1};
plot(b(:,2),b(:,1),'b','LineWidth',2);
xq = b(:,2);
yq = b(:,1);
h = imrect;
pos = getPosition(h);
X1 = round(pos(1));
Y1 = round(pos(2));
X2 = round(X1 + pos(3));
Y2 = round(Y1 + pos(4));
xv=[X1 X2];
yv=[Y1 Y2];
scatter(X1,Y1 ,'r')
scatter(X2,Y2 ,'r')
[in,on] = inpolygon(xq,yq,xv, yv) %xq and yq are inside or on the edge of the polygon area defined by xv and yv
您的意思是說pos是空的嗎?無論如何,你可能想在'pos = getPosition(h);'之前放一個'pause()''讓用戶調整矩形。否則,只要放置它,您就會立即閱讀它的位置。 – Zep
[in,on]僅顯示0和1,但不顯示座標。 – jane
'inpolygon'函數不會重新座標。它返回指示由xq和yq指定的查詢點是位於由xv和yv._定義的多邊形區域的內部還是邊緣上。它還返回指示查詢點是否位於多邊形區域的邊緣上。 – Zep