Andrei Cozma commited on
Commit
861a311
·
1 Parent(s): 0b750b0
generate_samples.py CHANGED
@@ -6,24 +6,25 @@ from scipy.ndimage import gaussian_filter
6
 
7
 
8
  def create_blank_image(size=256):
9
- return np.zeros((size, size), dtype=np.uint8)
 
10
 
11
 
12
  def add_horizontal_lines(image, spacing=10):
13
  for i in range(0, image.shape[0], spacing):
14
- image[i, :] = 255
15
  return image
16
 
17
 
18
  def add_vertical_lines(image, spacing=10):
19
  for i in range(0, image.shape[1], spacing):
20
- image[:, i] = 255
21
  return image
22
 
23
 
24
  def add_diagonal_lines(image, spacing=10):
25
  for i in range(0, image.shape[0], spacing):
26
- np.fill_diagonal(image[i:, i:], 255)
27
  return image
28
 
29
 
@@ -34,32 +35,32 @@ def add_circle(image, radius=50):
34
  -center_y : image.shape[0] - center_y, -center_x : image.shape[1] - center_x
35
  ]
36
  mask = x * x + y * y <= radius * radius
37
- image[mask] = 255
38
  return image
39
 
40
 
41
  def add_checkerboard(image, square_size=16):
42
  for i in range(0, image.shape[0], square_size * 2):
43
  for j in range(0, image.shape[1], square_size * 2):
44
- image[i : i + square_size, j : j + square_size] = 255
45
  image[
46
  i + square_size : i + square_size * 2,
47
  j + square_size : j + square_size * 2,
48
- ] = 255
49
  return image
50
 
51
 
52
- def add_horizontal_sinusoidal(image, frequency=1 / 20, amplitude=127):
53
  x = np.linspace(0, 1, image.shape[1])
54
- y = np.sin(2 * np.pi * frequency * x) * amplitude + 128
55
  for i in range(image.shape[0]):
56
  image[i, :] = y
57
  return image
58
 
59
 
60
- def add_vertical_sinusoidal(image, frequency=1 / 20, amplitude=127):
61
  x = np.linspace(0, 1, image.shape[0])
62
- y = np.sin(2 * np.pi * frequency * x) * amplitude + 128
63
  for i in range(image.shape[1]):
64
  image[:, i] = y
65
  return image
 
6
 
7
 
8
  def create_blank_image(size=256):
9
+ img = np.ones((size, size)) * 255
10
+ return img.astype(np.uint8)
11
 
12
 
13
  def add_horizontal_lines(image, spacing=10):
14
  for i in range(0, image.shape[0], spacing):
15
+ image[i, :] = 0
16
  return image
17
 
18
 
19
  def add_vertical_lines(image, spacing=10):
20
  for i in range(0, image.shape[1], spacing):
21
+ image[:, i] = 0
22
  return image
23
 
24
 
25
  def add_diagonal_lines(image, spacing=10):
26
  for i in range(0, image.shape[0], spacing):
27
+ np.fill_diagonal(image[i:, i:], 0)
28
  return image
29
 
30
 
 
35
  -center_y : image.shape[0] - center_y, -center_x : image.shape[1] - center_x
36
  ]
37
  mask = x * x + y * y <= radius * radius
38
+ image[mask] = 0
39
  return image
40
 
41
 
42
  def add_checkerboard(image, square_size=16):
43
  for i in range(0, image.shape[0], square_size * 2):
44
  for j in range(0, image.shape[1], square_size * 2):
45
+ image[i : i + square_size, j : j + square_size] = 0
46
  image[
47
  i + square_size : i + square_size * 2,
48
  j + square_size : j + square_size * 2,
49
+ ] = 0
50
  return image
51
 
52
 
53
+ def add_horizontal_sinusoidal(image, frequency=1 / 20, amplitude=255):
54
  x = np.linspace(0, 1, image.shape[1])
55
+ y = np.sin(2 * np.pi * frequency * x) * amplitude
56
  for i in range(image.shape[0]):
57
  image[i, :] = y
58
  return image
59
 
60
 
61
+ def add_vertical_sinusoidal(image, frequency=1 / 20, amplitude=255):
62
  x = np.linspace(0, 1, image.shape[0])
63
+ y = np.sin(2 * np.pi * frequency * x) * amplitude
64
  for i in range(image.shape[1]):
65
  image[:, i] = y
66
  return image
images/blank.png CHANGED
images/checkerboard.png CHANGED
images/circle.png CHANGED
images/diagonal.png CHANGED
images/horizontal.png CHANGED
images/horizontal_sinusoidal.png CHANGED
images/random_noise.png CHANGED
images/vertical.png CHANGED
images/vertical_sinusoidal.png CHANGED
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  gradio
2
  numpy
3
  Pillow
 
 
1
  gradio
2
  numpy
3
  Pillow
4
+ scipy