Himanshi commited on
Commit
85dd989
1 Parent(s): e9950ac

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +21 -0
utils.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+
4
+ def read_img(input_path) :
5
+ img = cv2.cvtColor(cv2.imread(input_path), cv2.COLOR_BGR2RGB)
6
+ return img
7
+
8
+ def edge_detection(img, line_wdt, blur):
9
+ gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
10
+ grayBlur = cv2.medianBlur(gray,blur)
11
+ edges = cv2.adaptiveThreshold(grayBlur, 255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,line_wdt,blur)
12
+ return edges
13
+
14
+ def color_quantisation(img, k):
15
+ data = np.float32(img).reshape((-1,3))
16
+ criteria = (cv2.TermCriteria_EPS + cv2.TERM_CRITERIA_MAX_ITER,20,0.001)
17
+ ret, label, center = cv2.kmeans(data,k,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
18
+ center = np.uint8(center)
19
+ result = center[label.flatten()]
20
+ result=result.reshape(img.shape)
21
+ return result