CG Lab
CG Lab
warpAffine(image,
translation_matrix, (image.shape[1],
import cv2 image.shape[0]))
def split_image(image_path): return translated_image
image = cv2.imread(image_path) def main():
height, width, _ = image.shape # Read the image
left = image[0:height, 0:width//2] image_path = "your_image_path.jpg" # Replace
right = image[0:height, width//2:width] with the path to your image
up = image[0:height//2, 0:width] original_image = cv2.imread(image_path)
down = image[height//2:height, 0:width] # Rotate the image
return left, right, up, down rotated_image = rotate_image(original_image,
def display_quadrants(left, right, up, down): 45)
cv2.imshow('Left Quadrant', left) # Scale the image
cv2.imshow('Right Quadrant', right) scaled_image = scale_image(original_image,
cv2.imshow('Upper Quadrant', up) 1.5)
cv2.imshow('Lower Quadrant', down) # Translate the image
cv2.waitKey(0) translated_image =
cv2.destroyAllWindows() translate_image(original_image, 50, 50)
def main(): # Display the images
image_path = "Your image name.jpg" cv2.imshow('Original Image', original_image)
left, right, up, down = split_image(image_path) cv2.imshow('Rotated Image', rotated_image)
display_quadrants(left, right, up, down) cv2.imshow('Scaled Image', scaled_image)
if __name__ == "__main__": cv2.imshow('Translated Image',
main() translated_image)
cv2.waitKey(0)
Program 8 cv2.destroyAllWindows()
if __name__ == "__main__":
import cv2 main()
import numpy as np
def rotate_image(image, angle):
height, width = image.shape[:2]
rotation_matrix =
cv2.getRotationMatrix2D((width/2, height/2),
angle, 1)
rotated_image = cv2.warpAffine(image,
rotation_matrix, (width, height))
return rotated_image
def scale_image(image, scale_factor):
scaled_image = cv2.resize(image, None,
fx=scale_factor, fy=scale_factor,
interpolation=cv2.INTER_LINEAR)
return scaled_image
def translate_image(image, tx, ty):
translation_matrix = np.float32([[1, 0, tx], [0, 1,
ty]])
Program 10 Program 11