Skip to main content
. 2019 Apr 6;5(4):45. doi: 10.3390/jimaging5040045
Algorithm 2 UpdateNeighbourhood
  • 1:

    ifLBthen         ▹ Select LAorD based on whether A (previous B) is an object pixel

  • 2:

       LAorD:=LB      ▹ Next value of LA

  • 3:

    else

  • 4:

       LAorD:=LX      ▹ Next value of LD

  • 5:

    end if

  • 6:

    LB:=LC

  • 7:

    LRB:=RB[C]       ▹ Look up position C in the row buffer

  • 8:

    ifLRBthen         ▹ An object pixel is coming into neighbourhood

  • 9:

       if ¬LC then        ▹ It is the first object pixel after a background pixel

  • 10:

         LMT:=MT[LRB]  ▹ First lookup in merger table

  • 11:

         if LMT=LRB then  ▹ Label was representative label

  • 12:

            LC:=LMT

  • 13:

         else

  • 14:

            LC:=MT[LMT]  ▹ Second lookup in merger table to get representative label

  • 15:

            if LCLMT then  ▹ Label change on second lookup indicates a chain

  • 16:

              MT[LRB]:=LC   ▹ Update merger table to unlink the chain

  • 17:

            end if

  • 18:

         end if

  • 19:

       else           ▹ Part of a run of consecutive pixels

  • 20:

         LC:=LC        ▹ Repeat latest label

  • 21:

         if LRBLRB then   ▹ Label has changed, indicating a chain of mergers

  • 22:

            MT[LRB]:=LC  ▹ Update merger table to unlink the chain

  • 23:

         end if

  • 24:

       end if

  • 25:

    else

  • 26:

       LC:=0        ▹ Lookup of background is unnecessary

  • 27:

    end if