Swapping heightmaps to depthmaps
Golfscript, 42 chars
n%{n*~]}%zip:|[]*$),{:);n|{{)&gt;},,}%}%-1%\;

results
$ golfscript 2657.gs &lt; 2657-1.txt 
0001
1012
1112
1212
2222
3323

$ golfscript 2657.gs &lt; 2657-2.txt 
01
12
22

$ golfscript 2657.gs &lt; 2657-3.txt 
010
211
322