Up-sampling and interpolation 

In order to improve the up-sampled output image quality, we can use some interpolation method such as bi-linear or bi-cubic interpolation. Let's see how.

Bi-linear interpolation

Let's consider a grayscale image, which is basically a 2D matrix of pixel values at integer grid locations. To interpolate the pixel value at any point P on the grid, the 2D analogue of linear interpolation: bilinear interpolation can be used. In this case, for each possible point P (that we would like to interpolate), four neighbors (namely, Q11Q12Q22, and Q21) are going to be there and the intensity values of these four neighbors are to be combined to compute the interpolated intensity at the point P, as shown in the following figure:

Let's use the PIL resize() function for bi-linear interpolation:

im1 = im.resize((im.width*5, im.height*5), Image.BILINEAR) # up-sample with bi-linear interpolation
pylab.figure(figsize=(10,10)), pylab.imshow(im1), pylab.show()

Here's the resized image. Notice how the quality improves when bi-linear interpolation is used with up-sampling:


Bi-cubic interpolation

It is an extension of cubic interpolation for interpolating data points on a 2D regular grid. The interpolated surface is smoother than corresponding surfaces obtained by bi-linear interpolation or nearest-neighbor interpolation.

Bi-cubic interpolation can be accomplished using either Lagrange polynomials, cubic splines, or the cubic convolution algorithm. PIL uses cubic spline interpolation in a 4 x 4 environment.

Let's use the PIL resize() function for bi-cubic interpolation:

im.resize((im.width*10, im.height*10), Image.BICUBIC).show()  # bi-cubic interpolation
pylab.figure(figsize=(10,10)), pylab.imshow(im1), pylab.show()

Look at how the quality of the resized image improves when we use bi-cubic interpolation:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.15.94