▁of ▁the ▁currently ▁set ▁pixels . ▁Un ique ▁pixels ▁are ▁retained ▁and ▁repeated ▁pixels ▁are ▁removed . ▁Set ▁the ▁pixels ▁indicated ▁by ▁Index ▁to ▁mark ▁in ▁the ▁connected - component ▁matrix . ▁In crement ▁the ▁marker ▁for ▁another ▁object ▁in ▁the ▁image . ▁▁ ▁One - Component - at - a - Time ( image ) ▁▁▁▁▁ ▁[ M , ▁N ] ▁:= ▁size ( image ) ▁▁▁▁▁ ▁connected ▁:= ▁zeros ( M , ▁N ) ▁▁▁▁▁ ▁mark ▁:= ▁value ▁▁▁▁▁ ▁difference ▁:= ▁increment ▁▁▁▁▁ ▁off sets ▁:= ▁[- 1 ; ▁M ; ▁ 1 ; ▁- M ] ▁▁▁▁▁ ▁index ▁:= ▁[] ▁▁▁▁▁ ▁no _ of _ objects ▁:= ▁ 0 ▁▁▁▁▁▁▁ ▁for ▁i : ▁ 1 : M ▁do ▁▁▁▁▁▁▁▁▁ ▁for ▁j : ▁ 1 : N ▁do ▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁if ▁( image ( i , ▁j ) ▁== ▁ 1 ) ▁then ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ ▁no _ of _ objects ▁:= ▁no _ of _ objects ▁+ ▁ 1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ ▁index ▁:= ▁[ (( j - 1 ) ▁× ▁M ▁+ ▁i )] ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ ▁connected ( index ) ▁:= ▁mark ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ ▁while ▁~ is empty ( index ) ▁do ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁ ▁image ( index ) ▁:= ▁ 0 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁ ▁neighb ors ▁:= ▁bs x fun (@ plus , ▁index , ▁off sets ) ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁ ▁neighb ors ▁:= ▁unique ( ne igh b ors (: )) ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁ ▁index ▁:= ▁neighb ors ( find ( image ( ne igh b ors ))) ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁ ▁connected ( index )