Spaces:
No application file
No application file
Create image
Browse files
image
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load image using OpenCV
|
| 6 |
+
image_path = "path_to_your_image.jpg"
|
| 7 |
+
image = cv2.imread(image_path)
|
| 8 |
+
|
| 9 |
+
# Resize the image
|
| 10 |
+
resized_image = cv2.resize(image, (300, 300))
|
| 11 |
+
|
| 12 |
+
# Rotate the image
|
| 13 |
+
(h, w) = resized_image.shape[:2]
|
| 14 |
+
center = (w // 2, h // 2)
|
| 15 |
+
rotation_matrix = cv2.getRotationMatrix2D(center, angle=45, scale=1.0)
|
| 16 |
+
rotated_image = cv2.warpAffine(resized_image, rotation_matrix, (w, h))
|
| 17 |
+
|
| 18 |
+
# Convert to grayscale
|
| 19 |
+
gray_image = cv2.cvtColor(rotated_image, cv2.COLOR_BGR2GRAY)
|
| 20 |
+
|
| 21 |
+
# Convert back to PIL format to save or display
|
| 22 |
+
output_image = Image.fromarray(gray_image)
|
| 23 |
+
output_image.save("transformed_image.jpg")
|
| 24 |
+
output_image.show()
|