Task 1:
Write a program to read a digital image, split and display the
image into 4 quadrants: up, down, left and right.
Input:
Output:
Explanation:
1. Through open cv library the image whose path has been encoded in the
code is read and detected.
2. The importation of data visualization library, Matplotlib leads to
visualization and display of the image read by the open cv library.
3. The Open CV can only detect and read images conforming to the BGR
format while the data visualization library can only showcase images
having the RGB format.
4. By using the cv2.cvtColor() function, we convert the format of the image
read by Open CV to RGB for matplotlib to showcase it.
5. Next, we obtain the dimensions of the image, i.e. the height, length and
colour channels of the image.
6. We calculate the midpoint or mid of the height and width of the image by
dividing the obtained height and width by 2.
7. Next, we segregate the image into 4 quadrants by using slicing method
to stipulate and outline each quadrant.
8. The height feature can be considered as rows while width as columns.
9. The top-left quadrant encompasses coordinates ranging from the initial
height coordinate to the mid of height and initial width coordinate to
mid coordinate.
10. The top-right coordinate encompasses the coordinates ranging from the
initial height coordinate to mid height coordinate, and the width
coordinate followed by the mid width coordinate.
11. The bottom left quadrant encompasses coordinates ranging from initial
width coordinate to the mid width coordinate, while the height
coordinate encompasses coordinate following the mid height
coordinate.
12. The bottom right quadrant encompasses the width coordinate which is
followed by the mid of width and the height also followed by the mid of
height.
13. We utilize a for loop to display all these 4 quadrants.
Task 2:
Give a program to show rotation, scaling and translation of
the same image.
Input:
Output:
Explanation:
1. After reading and converting the image into the Matplotlib-relevant
format, the coordinates i.e height and width of the image are obtained
while the colour channels are not factored in.
2. To rotate the image by a factor of 45 degrees, we will use the
.getRotationMatrix() that would create a matrix that would depict the
rotated image.
3. The parameters of the .getRotationMatrix() are the central
coordinates of the image and the degree by which we wish to rotate the
image.
4. The warpAffine() function serves the purpose of applying the rotation
matrix to the input image to depict the rotated image.
5. To scale the image, i.e resizing the image we use .resize() function and
resize the image by a factor of ½.