Matlab实现光速标签

问题描述 投票:0回答:1

我正在尝试实现本文中描述的光速标记技术的代码(我不能使用图像处理工具箱):https://pdfs.semanticscholar.org/ef31/7c257603004d818ca1e2a2aa67d36d40147e.pdf(参见第7页第2节)。

这是我的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 post Implementing LSL for Connected Component Labeling/Blob Extraction(我应用了建议的更改)中发现了一些C ++代码git repo https://github.com/prittt/YACCLAB/blob/master/include/labeling_lacassagne_2016_code.inc。我没有看到差异。

另外,我在理解等价类是什么时遇到了一些麻烦(这是矩阵EQ中的内容)。提前谢谢!

matlab connected-components labeling binary-image
1个回答
-2
投票

我意识到这有点晚了,但我只是提出了一段类似于光速标记算法的代码。我将简要介绍一下如何解决索引问题。

LSL的第一步是获取每列像素并找到连续标记像素的开始和停止位置。你可以在Matlab中这样做:

I = imread('text.png');
[rows,cols] = find(xor(I(2:end,:),I(1:end-1,:)));

这给你的是列中每个像素运行的开始和停止位置的行和列,除了它的非包含索引。通过非包容性索引,我的意思是对于每个像素运行(n),像素的指数从I(r(2*n-1),c(2*n-1))I(r(2*n)-1,c(2*n))。您应该注意,纸张沿着上面的代码沿着列操作的行操作,但是同样的原则适用。您还应注意,上述代码不包括图像边缘标记像素的情况。

如果你想看到完整的实现,我在Matlab文件交换中发布了我的代码。我没有声称它完全复制LSL,但它适用于许多相同的原则。

https://www.mathworks.com/matlabcentral/fileexchange/70323-ftllabel?s_tid=prof_contriblnk

© www.soinside.com 2019 - 2024. All rights reserved.