generated from Data-Science-Community-SRM/template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
3 - Detail_Enhancement_Filter.py
47 lines (27 loc) · 1 KB
/
3 - Detail_Enhancement_Filter.py
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
# -*- coding: utf-8 -*-
"""Detail Enhancement Filter.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/github/ankitasankars/Image-Cartoonization/blob/main/Detail_Enhancement_Filter.ipynb
### Importing libraries
"""
import numpy as np
import cv2
import matplotlib.pyplot as plt
from google.colab.patches import cv2_imshow
image_path = r"/content/Beetle.jpg"
image = cv2.imread(image_path)
plt.imshow(image)
"""### Applying Detail Enhancement Filter"""
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
plt.imshow(image_gray)
image_blur = cv2.medianBlur(image_gray, 3)
plt.imshow(image_blur)
image_edge = cv2.adaptiveThreshold(image_blur, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
plt.imshow(image_edge)
"""### Detail Enhancement filter
"""
image_color = cv2.detailEnhance(image, sigma_s=5, sigma_r=0.5)
plt.imshow(image_color)
image_cartoon = cv2.bitwise_and(image_color, image_color, mask=image_edge)
plt.imshow(image_cartoon)