![](http://images-20200215.ebookreading.net/23/1/1/9781482247336/9781482247336__a-computational-introduction__9781482247336__bg9b.png)
Image Geometry 137
MATLAB/Octave
>> hz = uint8(zeros(size(head)
*
2));
>> hz(1:2:2nd,1:2:end) = head;
>> imshow(hz)
>> imshow(imfilter(hz, [1 1 0;1 1 0;0 0 0])
>> imshow(imfilter(hz,[1 2 1;2 4 2;1 2 1]/4)
>> bfilt=[1 4 6 4 1;4 16 24 16 4;6 24 36 24 6;4 16 24 16 4;1 4 6 4 1]/64;
>> imshow(imfilter(hz,bfilt))
or in Python with
Python
In : r,c = head.shape
In : hz = np.zeros((2
*
r,2
*
c)).astype(’uint8’)
In : hz[::2,::2] = head
In : ne = array([[0,0,0],[0,1,1],[1,1,1]])
In : bi = array([[1,2,1],[2,4,2],[1,2,1]])/4.0
In : bc = array
([[1,4,6,4,1],[4,16,24,16,4],[6,24,36,24,6],[4,16,24,16,4],[1,4,6,4,1]])
/64.0
In : io.imshow(ndi.correlate(hz,ne))
and similarly for the others. The results are shown in Figure 6.16. We can enlarge more
by simply taking the result of the filter, applying a zero-interleave to it, and then another
filter.
Zero interleaving Nearest neighbor Bilinear Bicubic
FIGURE 6.16: Enlargement by spatial filtering
6.5 Scaling Smaller
The business of making an image smaller is also called image minimization; one way
is to take alternate pixels. If we wished to produce an image one-sixteenth the size of the
original, we would take out only those pixels (i, j) for which i and j are both multiples of
four. This method is called image subsampling and corresponds to the
nearest option of
imresize, and is very easy to implement.
However, it does not give very good results at high frequency components of an image.
We shall give a simple example; we shall construct a large image consisting of a white square
with a single circle on it. The
meshgrid command provides row and column indices which
span the array: