
Up-sampling
As discussed briefly in Chapter 1, Getting Started with Image Processing, in order to increase the size of an image we need to up-sample the image. The challenge is that the new larger images will have some pixels that have no corresponding pixel in the original smaller image, and we need to guess those unknown pixel values. We can guess the value of an unknown pixel using the following:
- An aggregate, for example, the mean value of its nearest known one or more pixel-neighbors values
- An interpolated value using pixel-neighbors with bi-linear or cubic interpolation
Nearest neighbor-based up-sampling may result in a poor quality output image. Let's code to verify this:
im = Image.open("../images/clock.jpg") # the original small clock image
pylab.imshow(im), pylab.show()
You'll see this, the original small clock image:
Let's now increase the width and height of the original image to a factor of five (thereby increasing the image size 25 times):
im1 = im.resize((im.width*5, im.height*5), Image.NEAREST) # nearest neighbor interpolation
pylab.figure(figsize=(10,10)), pylab.imshow(im1), pylab.show()
Here's the output of the nearest neighbor up-sampling, which does not work well; we obtain a larger pixelated image:
As we can see, the output image, created with the nearest-neighbor method, is 25 times larger than the input image, using the PIL library's resize() function. But clearly the output image is pixelated (with the blocking artifacts and jagged edges) and is of poor quality.