|
| 1 | +import numpy as np |
| 2 | +import cv2 |
| 3 | +import os.path |
| 4 | +from matplotlib import pyplot as plt |
| 5 | + |
| 6 | +img_path = input("Enter the path here:") #example -> C:\Users\xyz\OneDrive\Desktop\project\image.jpg |
| 7 | +img = cv2.imread(img_path) |
| 8 | +image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| 9 | + |
| 10 | +img_small = cv2.pyrDown(image) |
| 11 | +num_iter = 5 |
| 12 | +for _ in range(num_iter): |
| 13 | + img_small= cv2.bilateralFilter(img_small, d=9, sigmaColor=9, sigmaSpace=7) |
| 14 | + |
| 15 | +img_rgb = cv2.pyrUp(img_small) |
| 16 | + |
| 17 | +img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY) |
| 18 | +img_blur = cv2.medianBlur(img_gray, 7) |
| 19 | +img_edge = cv2.adaptiveThreshold(img_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, 2) |
| 20 | + |
| 21 | +img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB) |
| 22 | +array = cv2.bitwise_and(image, img_edge) |
| 23 | +array1 = cv2.bitwise_xor(array, image) |
| 24 | +plt.figure(figsize= (10,10)) |
| 25 | +plt.imshow(array1,cmap='gray') |
| 26 | +plt.title("Neon Effect Filtered Photo") |
| 27 | +plt.axis('off') |
| 28 | +filename = os.path.basename(image_path) |
| 29 | +plt.savefig("(Neon Effect Filter)"+filename) #saved file name as (Filtered)image_name.jpg |
| 30 | + |
| 31 | +plt.show() |
0 commit comments