▁Vincent ▁and ▁So ille ' s ▁waters hed ▁segment ation ▁algorithm , ▁other ▁implementations ▁also ▁exist . ▁ ▁In ▁order ▁to ▁do ▁that ▁a ▁linked ▁list ▁is ▁formed ▁that ▁will ▁keep ▁the ▁indexes ▁of ▁the ▁pixels ▁that ▁are ▁connected ▁to ▁each ▁other , ▁steps ▁( 2 ) ▁and ▁( 3 ) ▁below . ▁The ▁method ▁of ▁defining ▁the ▁linked ▁list ▁spec ifies ▁the ▁use ▁of ▁a ▁depth ▁or ▁a ▁bread th ▁first ▁search . ▁For ▁this ▁particular ▁application , ▁there ▁is ▁no ▁difference ▁which ▁strategy ▁to ▁use . ▁The ▁simplest ▁kind ▁of ▁a ▁last ▁in ▁first ▁out ▁queue ▁implemented ▁as ▁a ▁sing ly ▁linked ▁list ▁will ▁result ▁in ▁a ▁depth ▁first ▁search ▁strategy . ▁ ▁It ▁is ▁assumed ▁that ▁the ▁input ▁image ▁is ▁a ▁binary ▁image , ▁with ▁pixels ▁being ▁either ▁background ▁or ▁for eground ▁and ▁that ▁the ▁connected ▁components ▁in ▁the ▁for eground ▁pixels ▁are ▁desired . ▁The ▁algorithm ▁steps ▁can ▁be ▁written ▁as : ▁▁ ▁Start ▁from ▁the ▁first ▁pixel ▁in ▁the ▁image . ▁Set ▁current ▁label ▁to ▁ 1 . ▁Go ▁to ▁( 2 ). ▁ ▁If ▁this ▁pixel ▁is ▁a ▁for eground ▁pixel ▁and ▁it ▁is ▁not ▁already ▁label led , ▁give ▁it ▁the ▁current ▁label ▁and ▁add ▁it ▁as ▁the ▁first ▁element ▁in ▁a ▁queue , ▁then ▁go ▁to ▁( 3 ). ▁If ▁it ▁is ▁a ▁background ▁pixel ▁or ▁it ▁was ▁already ▁label led , ▁then ▁repeat ▁( 2 ) ▁for ▁the ▁next ▁pixel ▁in ▁the ▁image . ▁ ▁Pop ▁out ▁an ▁element ▁from ▁the ▁queue , ▁and