史蒂夫与MATLAB图像处理

图像处理的概念、算法和MATLAB

Feret属性——结束

今天,我想结束我Feret直径的长时间的讨论。(以前的帖子:29 - 9 - 2017,10月24日—- 2017,2月20 - - 2018,16 - 3月- 2018)。

回想一下,Feret直径测量物体沿一个特定方向的程度。下面的图表说明了这个概念。把对象测量内径的下巴,面向卡尺在指定的角。关闭下巴紧密的对象,同时保持这个角度。大白鲨是Feret直径之间的距离,角度。

最大Feret直径最低Feret直径测量一个物体的最大和最小宽度。在以前的文章中,我谈到了如何识别映顶点对设置的凸壳顶点加速的过程中找到这些最大和最小的措施。我也被认为是各种假设人可以对单个像素的形状,这些假设如何影响结果。(在这篇文章的其余部分,我将假设一个钻石像素形状,建议的短剑)。

让我们来看看这些几个特定对象的测量。

bw = imread (“shape.png”);imshow (bw)
visualizeFeretProperties (bw)

上面的第一个图显示了最大Feret直径及其取向。它也显示了Feret直径的角正交于最大直径。

第二个图是类似,除了它显示了最小Feret直径而不是正交的直径。你可以看到,他们是不一样的,一般来说,他们不会。

第三个图显示了最小区域边界框,可以使用一个搜索过程类似于最低Feret直径。在这个图中,注意这个边界框是不完全一致的方向最大Feret维度。一般来说,他们不一定会对齐,然后最小区域边界框的长度要小于最大Feret维度。

下面是我写了一个函数,将Feret直径属性添加到返回的表 regionprops(使用 “表”选项)。它使用的算法函数,你可以找到我之前的帖子。

T = regionprops (“表”bw,“PixelList”)
T =1×1表PixelList _________________(163875×2双)
T = feretProperties (T)
T =表1×12PixelList MaxFeretDiameter MaxFeretDiameterEndpoints MaxFeretDiameterOrientation MinFeretDiameter MinFeretDiameterTrianglePoints MinFeretDiameterOrientation OrthogonalDiameter OrthogonalDiameterLowerPoints OrthogonalDiameterUpperPoints MinAreaBoundingBox MinAreaBoundingBoxArea _________________ ___________ _________________________ ___________________________ ___________ ______________________________ ___________________________ _____________ _____________________________ _____________________________ _____________ ______________________(163875×2双)781.13(2×2双)-41.835 - 317.08(3×2双)-143.8 - 331.18(1×2双)[1×2双][5×2双]2.4321 e + 05

我希望至少几个你喜欢的这个转移成算法与对象相关的形状测量。

附录:函数使用

函数T = feretProperties (T)% 2017 - 2018版权MathWorks公司。maxfd = 0(高度(T) 1);maxfd_endpoints =细胞(高度(T) 1);maxfd_orientation = 0(高度(T) 1);minfd = 0(高度(T) 1);minfd_triangle_points =细胞(高度(T) 1);minfd_orientation = 0(高度(T) 1);minod = 0(高度(T) 1);minod_lower_points =细胞(高度(T) 1);minod_upper_points =细胞(高度(T) 1);minbb =细胞(高度(T) 1); minbb_a = zeros(height(T),1);k = 1:高度(T)像素= T.PixelList {k};V = pixelHull(像素,“钻石”);对= antipodalPairs (V);[maxfd (k), maxfd_endpoints {k}] = maxFeretDiameter (V,双);点= maxfd_endpoints {k};e =点(2:)——点(1:);maxfd_orientation (k) = atan2d (e (2), e (1));[minfd (k), minfd_triangle_points {k}] = minFeretDiameter (V,双);点= minfd_triangle_points {k};e =点(2:)——点(1:);thetad = atan2d (e (2), e (1)); minfd_orientation(k) = mod(thetad + 180 + 90,360) - 180; [minod(k),minod_lower_points{k},minod_upper_points{k}] =feretDiameter (V, maxfd_orientation (k) + 90);[minbb {k}, minbb_a (k)] = minAreaBoundingBox (V,双);结束T。MaxFeretDiameter = maxfd;T。MaxFeretDiameterEndpoints = maxfd_endpoints;T。MaxFeretDiameterOrientation = maxfd_orientation;T。MinFeretDiameter = minfd;T。MinFeretDiameterTrianglePoints = minfd_triangle_points; T.MinFeretDiameterOrientation = minfd_orientation; T.OrthogonalDiameter = minod; T.OrthogonalDiameterLowerPoints = minod_lower_points; T.OrthogonalDiameterUpperPoints = minod_upper_points; T.MinAreaBoundingBox = minbb; T.MinAreaBoundingBoxArea = minbb_a;结束函数(bb) = minAreaBoundingBox (V, antipodal_pairs)% 2017 - 2018版权MathWorks公司。如果输入参数个数< 2 antipodal_pairs = antipodalPairs (V);结束n =大小(antipodal_pairs, 1);p = antipodal_pairs (: 1);q = antipodal_pairs (:, 2);一个=正;thetad = [];k = 1: n如果k = = n k1 = 1;其他的k1 = k + 1;结束pt1 = [];pt2 = [];pt3 = [];如果(p (k) ~ = p (k1)) & & (q (k) = = q (k1)) pt1 = V (p (k):);pt2 = V (p (k1):);pt3 = V (q (k):);elseif(p (k) = = p (k1)) & & (q (k) ~ = q (k1)) pt1 = V (q (k):);pt2 = V (q (k1):);pt3 = V (p (k):);结束如果~ isempty (pt1)%点pt1 pt2, pt3可能最小区域%边界框,点pt1和pt2形成一条边重合%的边界框。叫三角形的高度与基础% pt1-pt2边界框的高度,h。h = triangleHeight (pt1 pt2 pt3);pt1pt2_direction = atan2d (pt2 (2) pt1 (2), pt2 (1) pt1 (1));w = feretDiameter (V, pt1pt2_direction);A_k = h * w;如果(A_k <) = A_k;thetad = pt1pt2_direction;结束结束结束%旋转所有的点,这样pt1-pt2最小边界框的点%直。r = 90 - thetad;cr = cosd (r);sr =信德(r);R = [cr老;sr cr);Vr = V * R ';xr = Vr (: 1);年= Vr (:, 2);xmin = min (xr);xmax = max (xr); ymin = min(yr); ymax = max(yr); bb = [xminyminxmaxyminxmaxymaxxminymaxxminymin];%旋转限位框点回来。bb = bb * R;结束函数h = triangleHeight (P1, P2, P3)% 2017 - 2018版权MathWorks公司。h = 2 * abs (signedTriangleArea (P1, P2, P3)) /规范(P1, P2);结束函数面积= signedTriangleArea (A, B, C)% 2017 - 2018版权MathWorks公司。面积= ((B (1) - (1)) * (C (2) - (2))(B (2) - (2)) * (C (1)——(1))) / 2;结束函数[d, V1、V2] = feretDiameter (V,θ)% 2017 - 2018版权MathWorks, Inc . %旋转点,这样感兴趣的方向是垂直的。α= 90 -θ;ca = cosd(α);sa =信德(α);R = [ca sa);sa ca);% Vr = (R * V ') ';Vr = V * R ';y = Vr (:, 2);ymin = min (y, [], 1); ymax = max(y,[],1); d = ymax - ymin; if nargout > 1 V1 = V(y == ymin,:); V2 = V(y == ymax,:);结束函数[d, end_points] = maxFeretDiameter (P, antipodal_pairs)% 2017 - 2018版权MathWorks公司。如果输入参数个数< 2 antipodal_pairs = antipodalPairs (P);结束v = P (antipodal_pairs (: 1):) - P (antipodal_pairs (:, 2):);D =函数(v (: 1), (2):,);[d, idx] = max (d, [], 1);P1 = P (antipodal_pairs (idx 1):);P2 = P (antipodal_pairs (idx 2):);end_points = [P1;P2);结束函数[d, triangle_points] = minFeretDiameter (V, antipodal_pairs)% 2017 - 2018版权MathWorks公司。如果输入参数个数< 2 antipodal_pairs = antipodalPairs (V);结束n =大小(antipodal_pairs, 1);p = antipodal_pairs (: 1);q = antipodal_pairs (:, 2);d =正;triangle_points = [];k = 1: n如果k = = n k1 = 1;其他k1 = k + 1;结束pt1 = [];pt2 = []; pt3 = []; if (p(k) ~= p(k1)) && (q(k) == q(k1)) pt1 = V(p(k),:); pt2 = V(p(k1),:); pt3 = V(q(k),:); elseif (p(k) == p(k1)) && (q(k) ~= q(k1)) pt1 = V(q(k),:); pt2 = V(q(k1),:); pt3 = V(p(k),:); end if ~isempty(pt1) % Points pt1, pt2, and pt3 form a possible minimum Feret diameter. % Points pt1 and pt2 form an edge parallel to caliper direction. % The Feret diameter orthogonal to the pt1-pt2 edge is the height % of the triangle with base pt1-pt2. d_k = triangleHeight(pt1,pt2,pt3); if d_k < d d = d_k; triangle_points = [pt1; pt2; pt3]; end end end end
|
  • 打印
  • 发送电子邮件

评论

留下你的评论,请点击在这里MathWorks账户登录或创建一个新的。