Image processing 无法理解双通道连接部件的伪代码
我在理解维基百科的伪代码时遇到了一些问题,该代码用于使用双通道算法标记连接的组件。以下是伪代码:Image processing 无法理解双通道连接部件的伪代码,image-processing,connected-components,Image Processing,Connected Components,我在理解维基百科的伪代码时遇到了一些问题,该代码用于使用双通道算法标记连接的组件。以下是伪代码: 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]
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
我的问题是行
链接的[NextLabel]=包含NextLabel的集合
。它从不初始化NextLabel,并且仍然使用它。还有,“包含NextLabel的集合”是什么意思?我真的被这段代码弄糊涂了。NextLabel
确实应该初始化,例如1。您需要了解Union Find算法才能理解这一点(因为它就是这样)@CrisLuengo那么这一行的解释在Union Find页面中?包含NextLabel的集合是Find(NextLabel)
,其中Find是“Union Find”数据结构的两个关键操作之一。@CrisLuengo哦,明白了!谢谢