
Image Geometry 135
MATLAB/Octave
>> [r,c] = size(m);
>> m2 = zeros(2
*
r,2
*
c);
>> m2(1:2:1
*
r,1:2:2
*
c) = m
ans =
16 0 2 0 3 0 13 0
0 0 0 0 0 0 0 0
5 0 11 0 10 0 8 0
0 0 0 0 0 0 0 0
9 0 7 0 6 0 12 0
0 0 0 0 0 0 0 0
4 0 14 0 15 0 1 0
0 0 0 0 0 0 0 0
In Python, interleaving is also easily done:
Python
In : m = array([[16,2,3,13],[5,11,10,8],[9,7,6,12],[4,14,15,1]]);
In : r,c = m.shape
In : m2 = zeros((2
*
r,2
*
c))
In : m2[::2,::2] = m
We can now replace the zeros by applying a spatial filter to this matrix. The spatial filters
1 1 0
1 1 0
0 0 0
1
4
1 2 1
2 4 2
1 2 1
implement nearest neighbor interpolation and bilinear interpolation, respectively. We can
test this with a