What is Cropping?
Cropping is the removal of unwanted outer areas from a photographic or illustrated image. The process usually consists of the removal of some of the peripheral areas of an image to remove extraneous trash from the picture, to improve its framing, to change the aspect ratio, or to accentuate or isolate the subject matter from its background.
We will be using these functions of OpenCV - python(cv2),
- imread(): This function is like it takes an absolute path of the file and reads the whole image, and after reading the whole image it returns us the image and we will store that image in a variable.
- imshow(): This function will be displaying a window (with a specified window name) which contains the image that is read by the imread() function.
- shape: This function will return the height, width, and layer of the image
Let’s take an example,
Let there be a list a=[1,2,3,4,5,6,7,8,9]
Now, here I just wanted the elements between 4 and 8
(including 4 and 8) so what we will do is :
print(a[3:8])
The result will be like : [4,5,6,7,8]
Python program to crop an image
Output:
You can see the Cropped Image and the Original Image(the cropping is done like 0.25 to 0.75 with row and with column 0.25 to 0.75, and you can change the number).
need an explanation for this answer? contact us directly to get an explanation for this answer