2013-04-17 31 views
-1

我已经计算出图像的质心,现在想要知道物体边界上距离质心最远点的坐标。质心最远点的坐标

我用下面的代码来计算最大距离。

boundaries = bwboundaries(pad); 
thisBoundary = boundaries{1}; 
boundaryX=thisBoundary(:,1); 
boundaryY=thisBoundary(:,2); 
% Get the distances of the boundary pixels from the centroid. 
distances= sqrt((boundaryX - a2).^2 + (boundaryY - b2).^2); 
% Scan the boundary to find the pixel on it that is 
% farthest from the centroid. 
maxRadius = max(distances); 
disp(maxRadius); 

如果有人知道如何计算物体边界上距离质心的最远点坐标,距离质心最远点的距离在上面计算为maxRadius。这里a2,b2是对象'pad'的质心坐标。

+1

请问如果有人知道是什么? – Jonas

+0

这不是问题...? – Dan

回答

3

在这里,您似乎在问“如何查找哪个输入值max已被选为最大值”。您需要使用max的第二个输出参数。对于你的具体情况,这给出了类似的东西:

[maxRadius, maxInd] = max(distances); 
maxCoord = thisBoundary(maxInd, :); 

请阅读the max function's documentation。下一次你也要问清楚一些确切的问题。

+0

谢谢!我得到了我所问的答案......但我意识到我的逻辑出错了。 – Suvidha

+0

我想计算物体的顶点。认为这将是最远的。但它不是:( – Suvidha