51: end loop

52: (*detect and process new minima at level *)

53: for all with im[p] = h do

54: dist [p] ← 0 (*reset distance to zero*)

55: if lab [p] = MASK then (*p is inside a new minimum*)

56: curlab ← curlab + 1; (*create new label*)

57: fifo_add (p, queue); lab[p] ← curlab

58: while not fifo_empty (queue) do

59: q ← fifo_remove (queue)

60: for all r ∈ N_G (q) do (*inspect neighbours of *)

61: if lab [r] = MASK then

62: fifo_add (r, queue); lab [r] ← cur lab

63: end if

64: end for

65: end while

66: end if

67: end for

68: end for

69: (*End Flooding*)