我正在尝试实现本文中描述的光速标记技术的代码(我不能使用图像处理工具箱):https ://pdfs.semanticscholar.org/ef31/7c257603004d818ca1e2a2aa67d36d40147e.pdf (参见第 2 节,第 7 页)。
这是我用于 LSL 等价构造的 Matlab 代码(算法 14,步骤 2)。
function [EQ,ERAi,nea] = LSL_equivalence(EQ,ERim1,RLCi,ERAim1,ERAi,NERi,nea,lImg)
% LSL_EQUIVALENCE build the associative table between er and ea
% GOAL: to create a Look Up Table to be applied to ERi to create EAi.
for er = 1:2:NERi % check segments one by one
% read the boundaries of each segment to obtain de relative labels of every agacent segment in the prev line
j0 = RLCi(er);
j1 = RLCi(er+1);
er0 = ERim1(j0+1); % label of the first segment
er1 = ERim1(j1+1); % the label of the last segment
% check label parity: segments are odd, background is even
% bitand([1 2 3 4 5],1) == [1 0 1 0 1]
if bitand(er0,1) == 0 % if er0 is even
er0 = er0 + 1;
end
if bitand(er1,1) == 0 % if er1 is even
er1 = er1 -1;
end
if er1 >= er0 % if there is an adjacency
ea = ERAim1(er0+1); % absolute label of the first segment
a = EQ(ea+1); % a is the ancestor (smallest label of the equivalence class)
for erk = (er0+2):2:er1
eak = ERAim1(erk+1);
ak = EQ(eak+1);
% min extraction and propagation
if a < ak
EQ(eak+1) = a;
else
a = ak;
EQ(ea+1) = a;
ea = eak;
end
end
ERAi(er+1) = a; % the global min of all ak ancestors
else % if there are no adjacent labels make a new label
nea = nea + 1;
ERAi(er+1) = nea;
end
end
end
我在使用索引时遇到了一些问题,因为文章中描述的伪代码的索引以 0 开头,而 Matlab 使用 1。我已经在 Stack Overflow 这篇文章为连接的组件标签/Blob 提取实现 LSL 中找到了一些 C++ 代码(我应用了建议的更改)以及此 git repo https://github.com/prittt/YACCLAB/blob/master/include/labeling_lacassagne_2016_code.inc。我看不到差异。
另外,我在理解什么是等价类(这是矩阵 EQ 中的内容)时遇到了一些麻烦。提前谢谢!