Binning a 2D array

If you always want a power-of-2 bin, repeated application of this works:

bin2(a) = a[1:2:end-1, 1:2:end-1] .+ a[2:2:end, 1:2:end-1] .+ a[1:2:end-1, 2:2:end] .+ a[2:2:end, 2:2:end]