2017-04-07 50 views
0

白點我有白色斑點該二進制圖像: Binary image 我想通過與光點的大小相同的矩形來表示每個白點和如有可能,相同的取向。有什麼功能可以做到這一點? 我可以檢測到每個點使用RP: enter image description here表示由矩形

回答

1

我會用相應的角度和垂直投影計算最小的費雷特直徑(最短投影)。這通常對應於最小的邊界框。

看到這裏的MATLAB代碼在計算費雷特直徑:http://www.crisluengo.net/index.php/archives/408

+0

謝謝。我會嘗試 –

0

你可以嘗試使用regionprops如下:

I = imread('tHZhy.png'); 
stats = regionprops(I, 'centroid', 'Orientation', 'MajorAxisLength','MinorAxisLength', 'BoundingBox'); 
figure 
imshow(I) 
hold on 
for i=1:length(stats) 
    xc = stats(i).Centroid; 
    ma = stats(i).MajorAxisLength/2; 
    mi = stats(i).MinorAxisLength/2; 
    theta = -deg2rad(stats(i).Orientation); 
    dx = [-ma -mi; ma -mi; ma mi; -ma mi; -ma -mi]; 
    R = [cos(theta) -sin(theta); sin(theta) cos(theta)]; % rotation matrix 
    x = xc + dx*R'; 
    plot(xc(1), xc(2), 'g*'); 
    plot(x(:, 1), x(:, 2), 'g'); 
end 

注意,結果是不完美的,尤其是對於相當多的對象。因此,其原因在於,當它沿着對角線指向時,主要維度是最大的。 enter image description here