寻找径向线段的最近邻

sle*_*led 5 algorithm matlab geometry nearest-neighbor feature-descriptor

首先,不要被这个问题的外表吓到;)

我正在尝试在 matlab 中实现一个称为圆形模糊形状模型的形状描述符,其中一部分是获取每个径向线段的最近邻居列表,如图 1d 所示)

我在 MATLAB 中进行了直接而简单的实现,但我停留在算法的第 5 步和第 6 步,主要是因为我无法理解定义:

Xb{c,s} = {b1, ..., b{c*s}} as the sorted set of the elements in B* 
so that d(b*{c,s}, bi*) <= d(b*{c,s}, bj*), i<j
Run Code Online (Sandbox Code Playgroud)

对我来说,这听起来像是级联排序,首先按升序排序,然后按升序排序,但我找到的最近邻居不是根据论文。

圆形模糊形状模型描述算法

作为示例,我向您展示了我为段 b{4,1} 获得的最近邻居,这是图 1d 中标记为“EX”的那个)

我得到以下 b{4,1} 的最近邻居列表: b{3,2}, b{3,1}, b{3,8}, b{2,1}, b{2,8}

根据论文正确的是: b{4,2}, b{4,8}, b{3,2}, b{3,1}, b{3,8}

然而,我的点实际上是最接近由欧几里德距离测量的选定线段的集合!距离b{4,1} <=> b{2,1}小于b{4,1} <=> b{4,2}b{4,1} <=> b{4,8}...

在此处输入图片说明

这是我的(丑陋但直接的)MATLAB 代码:

width  = 734;
height = 734;

assert(width == height, 'Image must be square in size!');

% Radius of the correlogram
R = width;

% Number of circles in correlogram
C = 4;

% Number of sections in correlogram
S = 8;

% "width" of ring segments
d = R/C;

% angle of one segment in degrees
g = 360/S;

% set of bins for the circular description of I
B = zeros(C, S);

% centroid coordinates for bins
B_star = zeros(C,S,2);


% calculate centroids of bins
for c=1:C
    for s=1:S
        alpha = deg2rad(max(s-1, 0)*g + g/2);
        r     = d*max((c-1),0) + d/2;

        B_star(c,s,1) = r*cos(alpha);
        B_star(c,s,2) = r*sin(alpha);
    end
end

% create sorted list of bin numbers which fullfill
% d(b{c,s}*, bi*) <= d(b{c,s}, bj*) where i<j

% B_star_dists is a simple square distance matrix for getting
% the distance between two centroids c_i,s_i and c_j,s_j
B_star_dists = zeros(C*S, C*S);
for i=1:C*S
    [c_i, s_i] = ind2sub([C,S], i);
    % x,y centroid coordinates for point i
    b_star_i   = [B_star(c_i, s_i, 1), B_star(c_i, s_i, 2)];

    for j=1:C*S
        [c_j, s_j] = ind2sub([C,S], j);
        % x,y centroid coordinates for point j
        b_star_j   = [B_star(c_j, s_j, 1), B_star(c_j, s_j, 2)];

        % store the euclidean distance between these two centroids
        % in the distance matrix.
        B_star_dists(i,j) = norm(b_star_i - b_star_j);
    end
end

% calculate nearest neighbour "centroids" for each centroid
% B_NN is a cell array, B{idx} gives an array of indexes to the 
% nearest neighbour centroids. 

B_NN = cell(C*S, 1);
for i=1:C*S
    [c_i, s_i] = ind2sub([C,S], i);

    % get a (C*S)x2 matrix of all distances, the first column are the array
    % indexes and the second column are the distances e.g
    % 1   d1
    % 2   d2
    % ..  ..
    % CS  d{c,s}

    dists = [transpose(1:C*S), B_star_dists(:, i)];

    % sort ascending by the distances first (e.g second column) then
    % sort ascending by the array index (e.g first column)
    dists = sortrows(dists, [2,1]);

    % middle section has nine neighbours, set as default
    neighbour_count = 9;

    if c_i == 1
        % inner region has S+3 neighbours
        neighbour_count = S+3;
    elseif c_i == C
        % outer most ring has 6 neighbours
        neighbour_count = 6;
    end

    B_NN{i} = dists(1:neighbour_count,1);
end

% FROM HERE ON JUST VISUALIZATION CODE

figure(1);
hold on;
for c=1:C
    % plot circles
    r = c*d;
    plot(r*cos(0:pi/50:2*pi), r*sin(0:pi/50:2*pi), 'k:');
end

for s=1:S
    % plot lines

    line_len = C*d;
    alpha    = deg2rad(s*g); 

    start_pt = [0, 0];
    end_pt   = start_pt + line_len.*[cos(alpha), sin(alpha)];

    plot([start_pt(1), end_pt(1)], [start_pt(2), end_pt(2)], 'k-');
end

for c=1:C
    % plot centroids of segments
    for s=1:S
        segment_centroid = B_star(c,s, :);
        plot(segment_centroid(1), segment_centroid(2), '.k');
    end
end

% plot some nearest neighbours
% list of [C;S] 
plot_nn = [4;1];

for i = 1:size(plot_nn,2) 
   start_c = plot_nn(1,i);
   start_s = plot_nn(2,i);

   start_pt = [B_star(start_c, start_s,1), B_star(start_c, start_s,2)];
   start_idx = sub2ind([C, S], start_c, start_s);

   plot(start_pt(1), start_pt(2), 'xb');

   nn_idx_list = B_NN{start_idx};

   for j = 1:length(nn_idx_list)
      nn_idx = nn_idx_list(j); 
      [nn_c, nn_s] = ind2sub([C, S], nn_idx);
      nn_pt = [B_star(nn_c, nn_s,1), B_star(nn_c, nn_s,2)];

      plot(nn_pt(1), nn_pt(2), 'xr');
   end
end
Run Code Online (Sandbox Code Playgroud)

完整的论文可以在这里找到

m69*_*g'' 2

论文谈“地区邻国”;认为这些是欧几里德距离意义上的“最近邻居”的解释是不正确的。它们只是某个区域的邻居区域,找到它们的方法很简单:

\n\n

这些区域有 2 个坐标:(c,s),其中 c 表示它们所属的同心圆,从中心的 1 到边缘的 C,s 表示它们所属的扇区,从 1 开始从角度 0\xc2\xb0 到 S,结束于角度 360\xc2\xb0。

\n\n

每个区域的 c 和 s 坐标与该区域的坐标最多相差 1,都是相邻区域(段号从 S 环绕到 1。)根据区域的位置,有 3 种情况:(如图所示图1d)

\n\n
    \n
  • 该区域是中间区域(标记为 MI),例如区域 b(2,4)
    \n有 2 个相邻圆和 2 个相邻扇区,因此总共 9 个区域:
    \n 圆 1、2 或 3 以及扇区 3、4 中的每个区域或 5:
    \nb(1,3), b(2,3), b(3,3), b(1,4), b(2,4), b(3,4), b(1,5), b(2,5), b(3,5)

  • \n
  • 该区域是一个内部区域(标记为 IN),例如区域 b(1,8)
    \n只有一个相邻圆和 2 个相邻扇区,但所有内部区域都是邻居,因此总共有 S + 3 个区域:
    \n中的每个区域圆 2 和扇区 7、8 或 1:
    \n \nb(2,7), b(2,8), b(2,1)
    以及内圆中的每个区域:
    \nb(1,1), b(1,2), b(1,3), b(1,4), b(1,5), b(1,6), b(1,7), b(1,8)

  • \n
  • 该区域是外部区域(标记为 EX),例如区域 b(3,1)
    \n只有一个相邻圆和 2 个相邻扇区,因此总共 6 个区域:
    \圆 2 或 3 以及扇区 8、1 或2:
    \nb(2,8), b(2,1), b(2,2), b(3,8), b(3,1), b(3,2)

  • \n
\n