Procedure run_length_classical
{
initialize
Run-Length and Union-Find data structures
count <- 0
/* Pass 1
(by rows) */
for
each current row and its previous row
{
move pointer P along the runs of
current row
move pointer Q along the runs of
previous row