难以理解两次通过连接组件的伪代码

我在理解Wikipedia用于使用两遍算法标记连接组件标签的伪代码时遇到了一些麻烦。这是伪代码:

algorithm TwoPass(data) is
linked = []
labels = structure with dimensions of data,initialized with the value of Background

First pass

for row in data do
    for column in row do
        if data[row][column] is not Background then

            neighbors = connected elements with the current element's value

            if neighbors is empty then
                linked[NextLabel] = set containing NextLabel
                labels[row][column] = NextLabel
                NextLabel += 1

            else

                Find the smallest label

                L = neighbors labels
                labels[row][column] = min(L)
                for label in L do
                    linked[label] = union(linked[label],L)

Second pass

for row in data do
    for column in row do
        if data[row][column] is not Background then
            labels[row][column] = find(labels[row][column])

return labels

我的问题在于行linked[NextLabel] = set containing NextLabel。它永远不会初始化NextLabel并仍然使用它。另外,“包含NextLabel的集合”是什么意思?这段代码让我很困惑。

hexiansheng108 回答:难以理解两次通过连接组件的伪代码

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1334738.html

大家都在问