2017-03-12 53 views
0

我想將斑馬線設置爲我的ROI。函數'roipoly'讓我定義一個感興趣的區域並返回一個二進制掩碼(這是我需要的下一步:vision.blobAnalysis)。獲取要用作roipoly參數的所需區域的座標

從外觀上看,這個我我想達到的目標:
enter image description here (是與覆蓋ROI可見矩形。)

Roipoly有區別的參數的變化:

BW = roipoly( I,c,r)和BW = roipoly(x,y,I,xi,yi)。如果我沒有弄錯c,r和x,y,xi,yi是座標。

我應該使用哪一種,以及如何提供座標參數?另外,如果你知道其他選擇來實現相同的目標,請賜教。 :)

回答

0

您可以使用getrect用鼠標選擇矩形,然後將選定的座標轉換爲roipoly輸入格式。

我用函數insertShape來繪製一個紅色的矩形。
(如果您無法訪問請求的工具箱,則可以使用其他方法)。

我使用的是BW = roipoly(I, c, r)版本,它的圖像大小爲圖像I

這裏是我的代碼:

%Read input image. 
I = imread('autumn.tif'); 
h = figure; 
imshow(I); 

%Specify rectangle with mouse 
rect = getrect(h); 

%Draw red rectangle (replace pixels data with red color). 
J = insertShape(I, 'Rectangle', rect, 'Color', [220, 0, 0], 'LineWidth', 3); 
imshow(J); 

%Compute rows and columns parameters from selected rect, to expected format of roipoly: 
% (x0,y0) is top left corner, and (x1,y1) is bottom right corner. 
x0 = rect(1); 
y0 = rect(2); 
x1 = x0 + rect(3) - 1; %rect(3) is width of rectangle. 
y1 = y0 + rect(4) - 1; %rect(4) is height of rectangle. 

%Imagine drawing lines from (x0,y0) to (x1,y0) to (x1,y1) to (x0,y1), [and back to (x0,y0), which closes the polygon] 
c = [x0, x1, x1, x0]; 
r = [y0, y0, y1, y1]; 

BW = roipoly(I, c, r); 
figure;imshow(BW); 

結果(選擇矩形後):
enter image description here

enter image description here

+0

非常感謝!!!! – Andre