block borders
 ;do a basin tessellation and tag the borders with the number of the
 ;cell on each side
 z3 = basins8(xq)
 ic = z3
 nx = dimen(z3,0)
 ny = dimen(z3,1)
 yq = ic(0:(nx-2), 0:(ny-2))
 yq2 = ic(1:*, 0:(ny-2))
 yq3 = ic(0:(nx-2), 1:*)
 sk = yq ne yq2 or yq ne yq3
 sk = sieve(sk)
 ;sk contains the coords of the boundaries biased to (0,0)
 ;now get the cell numbers for each border point
 sk1 = yq(sk)
 sk2 = yq2(sk)
 sk3 = yq3(sk)
 ;find two different ones
 ska = sk1
 skb = sk2
 in = sieve(ska eq skb)
 skb(in)=sk3(in)
 ;convert sk to full image indices
 skx = sk % (nx-1)	sky = sk/(nx-1)
 sk = skx + nx*sky
 ;make the border image
 bq = zero(xq)+!scalemin
 bq(sk) = !scalemax
 ;also make the random image
 tab = zero(z3)
 tab($basin_coords) = shuffle(indgen($basin_coords))
 tab = scale(tab(z3))
 endblock
 
