2017-05-28 42 views
0

我想用Matlab從所有四邊(左,右,上,下)中找出下圖中顯示的嵌套圓之間的距離。我發現這個圈子使用imfindcircle使用Matlab進行嵌套圓測量

下面是圖片:

OpticCupDisc Image

+0

如果你使用了'imfindcircle',那麼你有圓心和半徑。從那裏它只是算術。如果您在編碼解決方案時遇到問題,請發佈代碼以及您正在討論的*距離(最小,最大,平均值,所有距離?)。 – beaker

+0

是的,我有兩個值,但我不知道如何使用它。我需要從所有側面(頂部,底部,左側,右側)的外側圓的內側圓的邊緣之間找到距離 –

+0

您是否研究了距離度量[這裏](https://www.mathworks.com/help/stats/pdist2.html)? – kedarps

回答

0

您可以遵循這樣的事情。首先,從圖像中刪除白色背景。我在這裏使用了輸入,我假設你使用imfindcircle尋找圈子,所以你應該有中心在手。使用中心座標,我會畫出極端點,頂部,左側,底部和右側,然後計算這些點與中心之間的距離。

rgbImage = imread('JjkrL.jpg') ; 
%% Remove the white background 
grayImage = min(rgbImage, [], 3); 
binaryImage = grayImage < 200; 
binaryImage = bwareafilt(binaryImage, 1); 
[rows, columns] = find(binaryImage); 
row1 = min(rows); 
row2 = max(rows); 
col1 = min(columns); 
col2 = max(columns); 
% Crop 
croppedImage = rgbImage(row1:row2, col1:col2, :); 
[nx,ny,t] = size(croppedImage) ; 
imshow(croppedImage) ; 
%% 
% Centers of circles 
C1 = [84 142] ; 
C2 = [76 136] ; 

%% Get distances 
% circle 1/ Big circle 
% Edge points 
top = [C1(1) 1] ; 
bottom = [C1(1) nx] ; 
left = [1 C1(2)] ; 
right = [ny C1(2)] ; 
pts = [top ;left ;bottom ; right] ; 

hold on 
plot(C1(1),C1(2),'*r') 
plot(pts(:,1),pts(:,2),'*k') ; 
%% Get distances 
data = repmat(C1,[length(pts),1])-pts ; 
dist = sqrt(data(:,1).^2+data(:,2).^2);