O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cropping an image

Cropping an image means to extract a particular region of the image, which is smaller than the original image. This region in some books/references in called the Region of Interest (ROI). The concept of ROI is sometimes useful when you want to run your algorithm only on a particular part of the image and not the entire image. The image object has a crop() function that takes two coordinates--the upper-left corner and the bottom-right corner of the rectangle that you are interested in--and returns the cropped image:

>>> from PIL import Image>>> dim = (100,100,400,400) #Dimensions of the ROI>>> crop_img = img.crop(dim)>>> crop_img.show()

The following images shows the crop function as used in the preceding code:

Figure 3: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required