【问题标题】:Implementing connected component labeling for 8-connectivity using c++ for matrices as large as 1000 x 1000使用 c++ 为大至 1000 x 1000 的矩阵实现 8 连接的连接组件标记
【发布时间】:2012-06-22 06:33:30
【问题描述】:

如何在 C++ 中为大尺寸的二进制矩阵实现 CCL?我已经检查了维基百科中的算法,但我不明白如何解决它并实现数据结构来存储等价!任何帮助将不胜感激

【问题讨论】:

  • 我正在尝试为算法编写伪代码,并使用一个额外的矩阵进行标记

标签: c++ c algorithm graphics matrix


【解决方案1】:
Mark all nodes unassigned.

Iterate through all nodes:
    If node unassigned:
        Assign node to a new component id C
        Do a depth-first-search for all nodes connected to this one:
             mark them with same component id C

【讨论】:

  • 非常感谢您的回复。我应该使用数组来标记所有节点吗??
  • 是的。创建一个与矩阵大小相同的 int 数组。 0 初始化表示未分配。从 1 开始计数组件。
  • 非常感谢 :) 我会按照你说的解决问题。很快就会在这里更新。
【解决方案2】:

如果您不使用图表,请利用联合查找数据结构(也称为不相交集数据结构)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多