▁look ▁at ▁its ▁neighb ours ▁( based ▁on ▁any ▁type ▁of ▁connect ivity ). ▁If ▁a ▁neighbour ▁is ▁a ▁for eground ▁pixel ▁and ▁is ▁not ▁already ▁label led , ▁give ▁it ▁the ▁current ▁label ▁and ▁add ▁it ▁to ▁the ▁queue . ▁Re peat ▁( 3 ) ▁until ▁there ▁are ▁no ▁more ▁elements ▁in ▁the ▁queue . ▁ ▁Go ▁to ▁( 2 ) ▁for ▁the ▁next ▁pixel ▁in ▁the ▁image ▁and ▁increment ▁current ▁label ▁by ▁ 1 . ▁ ▁Note ▁that ▁the ▁pixels ▁are ▁label led ▁before ▁being ▁put ▁into ▁the ▁queue . ▁The ▁queue ▁will ▁only ▁keep ▁a ▁pixel ▁to ▁check ▁its ▁neighb ours ▁and ▁add ▁them ▁to ▁the ▁queue ▁if ▁necessary . ▁This ▁algorithm ▁only ▁needs ▁to ▁check ▁the ▁neighb ours ▁of ▁each ▁for eground ▁pixel ▁once ▁and ▁doesn ' t ▁check ▁the ▁neighb ours ▁of ▁background ▁pixels . ▁ ▁Two - pass ▁Rel atively ▁simple ▁to ▁implement ▁and ▁understand , ▁the ▁two - pass ▁algorithm , ▁( also ▁known ▁as ▁the ▁H os hen – K op el man ▁algorithm ) ▁iter ates ▁through ▁ 2 - dimensional ▁binary ▁data . ▁The ▁algorithm ▁makes ▁two ▁passes ▁over ▁the ▁image . ▁The ▁first ▁pass ▁to ▁assign ▁temporary ▁labels ▁and ▁record ▁equival ences ▁and ▁the ▁second ▁pass ▁to ▁replace ▁each ▁temporary ▁label ▁by ▁the ▁smallest ▁label ▁of ▁its ▁equivalence ▁class . ▁ ▁The ▁input ▁data ▁can ▁be ▁modified ▁in ▁situ ▁( which ▁car ries ▁the ▁risk ▁of ▁data ▁cor ruption ), ▁or ▁label ing ▁information ▁can ▁be ▁maintained ▁in ▁an ▁additional ▁data ▁structure