Remove boxes under preservation of shape
J, 73 chars

f=.3 :0
&gt;".'z',~,(',"','&amp;.&gt;/',~":)"*1+i.#$z=.(,$~$,~1#~(#$y)-#@$)&amp;.&gt;y
)


Usage and tests:

   a=.2 2 $ 0 ; 1 2 3 4 ; (,. 5 6 7 8) ; 9 + i. 4 4

   f a
0  1  2  3  4
5  9 10 11 12
6 13 14 15 16
7 17 18 19 20
8 21 22 23 24

   f a,:a  NB. rank 3 test
0  1  2  3  4
5  9 10 11 12
6 13 14 15 16
7 17 18 19 20
8 21 22 23 24

0  1  2  3  4
5  9 10 11 12
6 13 14 15 16
7 17 18 19 20
8 21 22 23 24


Golfing and explanation coming tomorrow.