-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageProcessing.py
More file actions
48 lines (36 loc) · 1.46 KB
/
Copy pathImageProcessing.py
File metadata and controls
48 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from PIL import Image
import os
import cv2
# ------ Flipping of Ambulance Text Image ------ #
# file_path = r"Ambulance.png"
# if os.path.exists(file_path):
# img = Image.open(file_path)
# transposeImg = img.transpose(Image.FLIP_LEFT_RIGHT)
# transposeImg.save("flippedAmbulance.png")
# print("Transpose is Done!")
# else:
# print("Error: File not found! Please check the path.")
img= cv2.imread(r"DhakshuScenery.jpg") # Read the Image using 'imread()'
# Ensure the image is loaded
if img is None:
print("Error: File not found! Check the path.")
exit()
# Convert to Gray Color
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 1️⃣ CLAHE - Contrast-Limited Adaptive Histogram Equalization
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
clahe_img = clahe.apply(gray_img)
# 2️⃣ Gaussian Blur (Smooth Effect)
gaussian_blur = cv2.GaussianBlur(img, (15, 15), 0)
# 3️⃣ Edge Detection (Canny Edge Filter)
edges = cv2.Canny(img, 100, 200)
# 4️⃣ Sketch Effect (Invert + Blur + Divide)
inv_gray = 255 - gray_img
blurred = cv2.GaussianBlur(inv_gray, (21, 21), 0)
sketch = cv2.divide(gray_img, 255 - blurred, scale=256)
# Save the filtered images
cv2.imwrite("Dhakshu_CLAHE.jpg", clahe_img)
cv2.imwrite("Dhakshu_GaussianBlur.jpg", gaussian_blur)
cv2.imwrite("Dhakshu_EdgeDetection.jpg", edges)
cv2.imwrite("Dhakshu_SketchEffect.jpg", sketch)
print("✅ All filters applied and saved successfully!")