【问题标题】:Matlab - neighbouring clusters (in two different matrices)Matlab - 相邻簇(在两个不同的矩阵中)
【发布时间】:2013-12-20 13:53:28
【问题描述】:

给定两个矩阵 A 和 B(大小相同 - 都只包含 1 和 0)以及在这两个矩阵上使用 bwconncomp 的相关结构。

如何确定矩阵 A 中的簇(其位置包含在 CC.PixelIdcList 中)是否具有与矩阵 B 中的簇之一中的像素位置匹配的位置的相邻像素?

我想创建一个列表,其中包含矩阵 A 中每个簇的 id 和与其相邻的簇的 id(在矩阵 B 中)以及在矩阵 B 中具有位置匹配簇的相邻像素的位置。

ID 簇(来自 A)- ID 簇(来自 B)- 位置

【问题讨论】:

    标签: matlab comparison cluster-analysis


    【解决方案1】:

    我认为放弃使用bwconncomp 而是使用bwlabel(或bwlabeln,如果这是N 维)可能更简单。

    [labelA, numA] = bwlabel (mA);
    [labelB, numB] = bwlabel (mB);
    
    inter = labelA & labelB;
    
    cluster_ind = unique (labelA(inter));
    
    match_cluster = repmat ({[]}, numA, 1);
    match_ind     = repmat ({[]}, numA, 1);
    for idx = cluster_ind
      %% index with IDs from A to get...
      %% ... an array with IDs from B that intersect it
      match_clusters{idx} = unique (labelB(labelA == idx));
      %% ... linear indices for the elements that match something in B 
      match_ind{idx} = find (labelA === idx);
    end
    

    我假设您在将原始图像提供给 bwconncomp 之前拥有原始图像,如果没有,从其输出重建标签图像应该是微不足道的。

    【讨论】:

    • 谢谢你这可能有效。但是我有一个问题。我想查找矩阵 A 中的点周围簇是否位于与矩阵 B 中的簇相对应的位置。我可以使用 bwdist(A,'chessboard') 来查找周围点并制作矩阵 C 进行比较。然而,问题是矩阵 B 中的单独簇可能会组合在一起,如果簇靠得很近。
    • @Mykje 集群 A 周围的点是什么意思?你不需要使用bwdist,这是非常无用的。您可以使用适当大小的 SE 对图像进行扩张,并减去原始图像以获得周围的像素。但这是一个单独的问题。
    • 两个矩阵中簇的位置没有重叠。但是,矩阵 B 中的所有簇都将位于距矩阵 A 中的簇仅一个像素(它们最近的位置)。我需要知道哪些簇是相邻的以及相邻点是什么。
    • @Mykje 然后在使用矩阵 A 调用 bwlabel 之前,使用 mA = imdilate (mA, [0 1 0; 1 1 1; 0 1 0]) 将其扩展一个像素,这将仅在垂直和水平上扩展一个像素。您也可以使用true (3) 在对角线上扩展它。
    猜你喜欢
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多