Files changed (1) hide show
  1. xdog.py +10 -21
xdog.py CHANGED
@@ -12,25 +12,17 @@ def dog(img,size=(0,0),k=1.6,sigma=0.5,gamma=1):
12
  # Threshold the dog image, with dog(sigma,k) > 0 ? 1(255):0(0)
13
  def edge_dog(img,sigma=0.5,k=200,gamma=0.98):
14
  aux = dog(img,sigma=sigma,k=k,gamma=0.98)
15
- for i in range(0,aux.shape[0]):
16
- for j in range(0,aux.shape[1]):
17
- if(aux[i,j] > 0):
18
- aux[i,j] = 255
19
- else:
20
- aux[i,j] = 0
21
  return aux
22
 
23
  # garygrossi xdog version
24
  def xdog_garygrossi(img,sigma=0.5,k=200, gamma=0.98,epsilon=0.1,phi=10):
25
  aux = dog(img,sigma=sigma,k=k,gamma=gamma)/255
26
- for i in range(0,aux.shape[0]):
27
- for j in range(0,aux.shape[1]):
28
- if(aux[i,j] >= epsilon):
29
- aux[i,j] = 1
30
- else:
31
- ht = np.tanh(phi*(aux[i][j] - epsilon))
32
- aux[i][j] = 1 + ht
33
- return aux*255
34
 
35
  def hatchBlend(image):
36
  xdogImage = xdog(image,sigma=1,k=200, gamma=0.5,epsilon=-0.5,phi=10)
@@ -42,13 +34,10 @@ def hatchBlend(image):
42
  # version of xdog inspired by article
43
  def xdog(img,sigma=0.5,k=1.6, gamma=1,epsilon=1,phi=1):
44
  aux = dog(img,sigma=sigma,k=k,gamma=gamma)/255
45
- for i in range(0,aux.shape[0]):
46
- for j in range(0,aux.shape[1]):
47
- if(aux[i,j] < epsilon):
48
- aux[i,j] = 1*255
49
- else:
50
- aux[i,j] = 255*(1 + np.tanh(phi*(aux[i,j])))
51
- return aux
52
 
53
  def to_sketch(img_orig, sigma=0.3, k=4.5, gamma=0.95, epsilon=-1, phi=10e15, area_min=2):
54
  img_cnts = []
 
12
  # Threshold the dog image, with dog(sigma,k) > 0 ? 1(255):0(0)
13
  def edge_dog(img,sigma=0.5,k=200,gamma=0.98):
14
  aux = dog(img,sigma=sigma,k=k,gamma=0.98)
15
+ aux[aux>0] = 255
16
+ aux[aux<=0] = 0
 
 
 
 
17
  return aux
18
 
19
  # garygrossi xdog version
20
  def xdog_garygrossi(img,sigma=0.5,k=200, gamma=0.98,epsilon=0.1,phi=10):
21
  aux = dog(img,sigma=sigma,k=k,gamma=gamma)/255
22
+ aux_copy = aux.copy()
23
+ aux_copy[aux >= epsilon] = 1
24
+ aux_copy[aux < epsilon] = 1 + np.tanh(phi*(aux[aux < epsilon] - epsilon))
25
+ return aux_copy*255
 
 
 
 
26
 
27
  def hatchBlend(image):
28
  xdogImage = xdog(image,sigma=1,k=200, gamma=0.5,epsilon=-0.5,phi=10)
 
34
  # version of xdog inspired by article
35
  def xdog(img,sigma=0.5,k=1.6, gamma=1,epsilon=1,phi=1):
36
  aux = dog(img,sigma=sigma,k=k,gamma=gamma)/255
37
+ aux_copy = aux.copy()
38
+ aux_copy[aux >= epsilon] = 255*(1 + np.tanh(phi*(aux[aux>=epsilon])))
39
+ aux_copy[aux < epsilon] = 255
40
+ return aux_copy
 
 
 
41
 
42
  def to_sketch(img_orig, sigma=0.3, k=4.5, gamma=0.95, epsilon=-1, phi=10e15, area_min=2):
43
  img_cnts = []