
130 A Computational Introduction to Digital Image Processing, Second Edition
MATLAB/Octave
>> c = imread(’cameraman.png’);
>> head = c(33:96,90:153);
>> imshow(head)
>> head4n = imresize(head,4,’nearest’);imshow(head4n)
>> head4b = imresize(head,4,’bilinear’);imshow(head4b)
Python has a rescale function in the transform module of skimage:
Python
In : c = io.imread(’cameraman.png’)
In : head = c[32:96,89:153]
In : io.imshow(head)
In : head4n = tr.rescale(head,2,order=0)
In : head4n = tr.rescale(head,2,order=1)
The order parameter of the rescale method provides the order of the interpolating p oly-
nomial: 0 corresponds to nearest neighbor and 1 to bilinear ...