Write a Program to read a digital image. Split and display image into 4 quadrants, up, down, right and left

Write a Program to read a digital image. Split and display image into 4 quadrants, up, down, right and left

Program:

import cv2

# Read the image
img = cv2.imread("atc.jpg")  # Replace with the path to your image

# Get the height and width of the image
h, w, _ = img.shape
half_height, half_width = h // 2, w // 2

# Split the image into four quadrants
TopLeft_quadrant = img[:half_height, :half_width]
TopRight_quadrant = img[:half_height, half_width:]
BottomLeft_quadrant = img[half_height:, :half_width]
BottomRight_quadrant = img[half_height:, half_width:]

# Display the original image and the quadrants
cv2.imshow('Original Image', img)
cv2.imshow('Top Left Quadrant', TopLeft_quadrant)
cv2.imshow('Top Right Quadrant', TopRight_quadrant)
cv2.imshow('Bottom Left Quadrant', BottomLeft_quadrant)
cv2.imshow('Bottom Right Quadrant', BottomRight_quadrant)

cv2.waitKey(0)
cv2.destroyAllWindows()

Leave a Reply

Your email address will not be published. Required fields are marked *