▁for ▁row ▁in ▁data ▁do ▁▁▁▁▁▁▁▁▁ ▁for ▁column ▁in ▁row ▁do ▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁if ▁data [ row ][ column ] ▁is ▁not ▁Background ▁then ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ ▁labels [ row ][ column ] ▁= ▁find ( labels [ row ][ column ]) ▁▁▁▁▁▁▁▁▁ ▁return ▁labels ▁ ▁The ▁find ▁and ▁union ▁algorithms ▁are ▁implemented ▁as ▁described ▁in ▁union ▁find . ▁ ▁Se qu ential ▁algorithm ▁ ▁Create ▁a ▁region ▁counter ▁ ▁Sc an ▁the ▁image ▁( in ▁the ▁following ▁example , ▁it ▁is ▁assumed ▁that ▁sc anning ▁is ▁done ▁from ▁left ▁to ▁right ▁and ▁from ▁top ▁to ▁bottom ): ▁▁ ▁For ▁every ▁pixel ▁check ▁the ▁north ▁and ▁west ▁pixel ▁( when ▁considering ▁ 4 - connect ivity ) ▁or ▁the ▁n ortheast , ▁north , ▁north west , ▁and ▁west ▁pixel ▁for ▁ 8 - connect ivity ▁for ▁a ▁given ▁region ▁criter ion ▁( i . e . ▁intensity ▁value ▁of ▁ 1 ▁in ▁binary ▁image , ▁or ▁similar ▁intensity ▁to ▁connected ▁pixels ▁in ▁gray - scale ▁image ). ▁ ▁If ▁none ▁of ▁the ▁neighb ors ▁fit ▁the ▁criter ion ▁then ▁assign ▁to ▁region ▁value ▁of ▁the ▁region ▁counter . ▁ ▁In crement ▁region ▁counter . ▁ ▁If ▁only ▁one ▁neighbor ▁fits ▁the ▁criter ion ▁assign ▁pixel ▁to ▁that ▁region . ▁ ▁If ▁multiple ▁neighb ors ▁match ▁and ▁are ▁all ▁members ▁of ▁the ▁same ▁region , ▁assign ▁pixel ▁to ▁their ▁region . ▁ ▁If ▁multiple ▁neighb ors ▁match ▁and ▁are ▁members ▁of ▁different ▁regions , ▁assign ▁pixel ▁to ▁one ▁of ▁the ▁regions ▁( it ▁doesn '