【问题标题】:Represent white spots by rectangles用矩形表示白点
【发布时间】:2017-04-07 14:35:02
【问题描述】:

我有这个带有白点的二进制图像: 我想用一个大小相同的矩形来表示每个白点,如果可能的话,方向相同。有什么功能可以做到这一点? 我可以使用 RP 检测每个点:

【问题讨论】:

    标签: matlab rectangles region drawrectangle


    【解决方案1】:

    我将计算具有相应角度的最小费雷特直径(最短投影)和垂直投影。这通常对应于最小的边界框。

    有关计算 Feret 直径的 MATLAB 代码,请参见此处:http://www.crisluengo.net/archives/408

    【讨论】:

      【解决方案2】:

      您可以尝试使用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
      

      请注意,结果并不完美,尤其是对于相当方形的对象。因此,原因是当主维度沿对角线方向时最大。

      【讨论】:

        猜你喜欢
        • 2012-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-24
        • 2019-07-29
        • 1970-01-01
        • 2021-02-19
        相关资源
        最近更新 更多