1

https://www.lri.fr/~lacas/Publications/JRTIP10.pdfから Light Speed Labeling アルゴリズムを実装しようとしています。この論文に記載されているアルゴリズムのアプローチにできる限り厳密に従おうとしましたが (pgs 9-12)、同等化段階の後の出力は意味がありません。

問題が何であるか誰にも分かりますか?

void segment(const unsigned * Xi, const unsigned& N, unsigned * ERi, unsigned *RLCi, unsigned& ner) 
{ 
unsigned x1     = 0;
unsigned f      = 0;
unsigned er     = 0;    

for (unsigned j = 0; j < N; ++j)
{
    const unsigned x0 = Xi[j];
    f = x0 ^ x1;
    RLCi[er] = j;         
    er = er + f;
    ERi[j] = er;         
    x1 = x0;        
}    
if (x1 != 0)
{
    RLCi[er] = N;
}
er = er + x1;
ner = er;
}

void equivalance(const unsigned& ner, unsigned * RLCi, unsigned * EQ, unsigned * ER0, unsigned * ERA0, unsigned * ERA1, unsigned& nea, const unsigned& N = 0)
{
for (unsigned er = 1; er <= ner; er += 2)
{        
    int j0 = RLCi[er - 1];
    int j1 = RLCi[er] - 1;
   // Unnecessary given optimization and need for 4-connectivity:
    // if (j0 > 0) j0 = j0 - 1;
   // if (j1 < N - 1) j1 = j1 + 1;

    int er0 = ER0[j0];
    int er1 = ER0[j1];

    if (!(er0 & 1)) er0 = er0 + 1;
    if (!(er1 & 1)) er1 = er1 - 1;       

    if (er1 >= er0) // adjacent label
    {            
        unsigned ea = ERA0[er0];
        unsigned a = EQ[ea];
        for (unsigned erk = er0 + 2; erk <= er1; ++erk)
        {
            unsigned eak = ERA0[erk];              
            unsigned ak = EQ[eak];
            if (a < ak)
            {
                EQ[eak] = a;
            }
            else
            {
                a = ak;                    
                EQ[ea] = a;
                ea = eak;
            }                
        }           
        ERA1[er] = a;
    }
    else
    {
        nea = nea + 1;
        ERA1[er] = nea;
    }
}   
}

typedef std::vector<unsigned> value_type;
void bwlabel(const double* X, unsigned * EA, const unsigned& N, const unsigned& M)
{
unsigned nea = 0;
const unsigned size = N * M;

value_type EQ(size, 0), ER(size, 0), ERA(size, 0), A(size, 0), RLC(M * (2 * N), 0), IN(X, X + size), NER(M, 0);

// Step 1
for (int m = 0; m < M; ++m)
{        
    segment(&IN[0] + N * m, N, &ER[0] + N * m, &RLC[0] + m * (2 * N), NER[m]);       
}    
// Step 2
for (int m = 1; m < M; ++m)
{        
    equivalance(NER[m], &RLC[0] + m * (2 * N), &EQ[0], &ER[0] + (m - 1) * N, &ERA[0] + (m - 1) * N, &ERA[0] + m * N, nea, N);               
}
// Step 3
for (int j = 0; j < size; ++j)
{
    EA[j] = ERA[ER[j]];        
} 

// Step 4
unsigned na = 0;
for (int e = 0; e < size; ++e)
{
    if (EQ[e] != e)
    {
        A[e] = EQ[EQ[e]];
    }
    else
    {
        na = na + 1;
        A[e] = na;
    }
}
// Step 5
for (int j = 0; j < size; ++j)
{
    EA[j] = A[EA[j]];
}
}
IN=
1 1 0 1 1 0 0 1 1 1 
0 1 1 0 1 0 0 1 1 1 
1 0 1 1 1 1 1 0 1 0 
1 0 0 0 0 1 1 0 1 0 
0 0 1 1 0 0 0 1 1 1 
0 1 1 0 0 0 1 0 1 0 
1 0 1 1 1 1 1 0 0 0 
1 0 1 0 1 0 0 0 1 0 
0 1 1 1 1 0 1 1 0 1 
0 0 1 1 1 0 1 0 0 0 


RLC=
[0]0 [1]2 [2]3 [3]5 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 
[0]1 [1]3 [2]4 [3]5 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]1 [2]2 [3]7 [4]8 [5]9 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]1 [2]5 [3]7 [4]8 [5]9 [6]0 [7]0 [8]0 [9]0 
[0]0 [1]0 [2]0 [3]0 [4]0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