In order to decrease the size of an image, we need to down-sample the image. For each pixel in the new smaller image, there will be multiple pixels in the original larger image. We can compute the value of a pixel in the new image by doing the following:
- Dropping some pixels (for example, dropping every other row and column if we want an image a fourth of the size of the original image) from the larger image in a systematic way
- Computing the new pixel value as an aggregate value of the corresponding multiple pixels in the original image
Let's use the tajmahal.jpg image and resize it to an output image of a size 25 times smaller than the input image using the resize() function, again from the PIL library:
im = Image.open("../images/tajmahal.jpg") ...