sumau's picture
Create image
7974d31 verified
from PIL import Image
import cv2
import numpy as np
# Load image using OpenCV
image_path = "path_to_your_image.jpg"
image = cv2.imread(image_path)
# Resize the image
resized_image = cv2.resize(image, (300, 300))
# Rotate the image
(h, w) = resized_image.shape[:2]
center = (w // 2, h // 2)
rotation_matrix = cv2.getRotationMatrix2D(center, angle=45, scale=1.0)
rotated_image = cv2.warpAffine(resized_image, rotation_matrix, (w, h))
# Convert to grayscale
gray_image = cv2.cvtColor(rotated_image, cv2.COLOR_BGR2GRAY)
# Convert back to PIL format to save or display
output_image = Image.fromarray(gray_image)
output_image.save("transformed_image.jpg")
output_image.show()