【发布时间】:2017-03-23 02:55:39
【问题描述】:
我有一个不规则形状的物体,我必须在其中找到最大和最小直径。
为了找到最大直径,我提取了边界点并找到了所有点之间的距离。在那些给我最大直径的距离中,我选择了最大距离。
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for blobIndex = 1 : numberOfBoundaries
thisBoundary = boundaries{blobIndex};
x = thisBoundary(:, 2); % x = columns.
y = thisBoundary(:, 1); % y = rows.
% Find which two boundary points are farthest from each other.
maxDistance = -inf;
for k = 1 : length(x)
distances = sqrt( (x(k) - x) .^ 2 + (y(k) - y) .^ 2 );
[thisMaxDistance, indexOfMaxDistance] = max(distances);
if thisMaxDistance > maxDistance
maxDistance = thisMaxDistance;
index1 = k;
index2 = indexOfMaxDistance;
end
end
我附上了包含最长直径的图片。
我还需要一条穿过质心的线段,连接长度最短的两个边界点。当我尝试通过修改上述代码来找到最短直径时,找到min(distances),我收到一条错误消息:
使用
griddedInterpolant时出错 输入点的坐标必须是有限值;不允许使用Inf和NaN。
我需要怎么做才能找到这个物体的最短“直径”(即通过质心)?
【问题讨论】:
-
哪一行给你这个错误?
-
当我取最小(距离)时,我得到了零。这可能就是我收到错误的原因。我找到最短直径的逻辑对吗?
-
当您将
max更改为min时,您会寻找距离最近的两个边界点。显然,这将是边界的任何点及其本身,距离为零。 -
如果您发布在代码开头使用的
binaryImage,我可能会提供帮助。 -
我已经编辑了我的问题并附上了图片。请指导。
标签: matlab geometry line shape min