marta-marta commited on
Commit
9e671c6
·
1 Parent(s): 85321d7

Testing how to improve piecewise functions

Browse files
Data_Generation/Piecewise_Box_Functions.py CHANGED
@@ -1,8 +1,8 @@
1
  import numpy as np
2
  from scipy import signal
3
  import math
4
-
5
-
6
  def basic_box_array(image_size):
7
  A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
8
  # Creates the outside edges of the box
@@ -69,20 +69,75 @@ def hamburger_array(image_size):
69
  # if array_new[i][j] == 1:
70
  # A[i][j] = 1
71
  # return A
72
- def update_array(array_original, array_new, image_size):
73
  A = array_original
74
  A[array_new == 1] = 1
75
  return A
76
 
77
 
78
- def add_pixels(array_original, additional_pixels):
79
- # Adds pixels to the thickness of each component of the box
 
 
 
 
 
 
 
 
 
 
 
 
80
  A = array_original
81
- filter = np.array(([0, 1, 0], [1, 1, 1], [0, 1, 0])) # This filter will only add value where there are pixels on
82
- # the top, bottom, left or right of a pixel
83
-
84
- # This filter adds thickness based on the desired number of additional pixels
85
- for item in range(additional_pixels):
86
- convolution = signal.convolve2d(A, filter, mode='same')
87
- A = np.where(convolution <= 1, convolution, 1)
88
- return A
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import numpy as np
2
  from scipy import signal
3
  import math
4
+ import matplotlib.pyplot as plt
5
+ import itertools
6
  def basic_box_array(image_size):
7
  A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
8
  # Creates the outside edges of the box
 
69
  # if array_new[i][j] == 1:
70
  # A[i][j] = 1
71
  # return A
72
+ def update_array(array_original, array_new):
73
  A = array_original
74
  A[array_new == 1] = 1
75
  return A
76
 
77
 
78
+ # def add_pixels(array_original, additional_pixels):
79
+ # # Adds pixels to the thickness of each component of the box
80
+ # A = array_original
81
+ # filter = np.array(([0, 1, 0], [1, 1, 1], [0, 1, 0])) # This filter will only add value where there are pixels on
82
+ # # the top, bottom, left or right of a pixel
83
+ #
84
+ # # This filter adds thickness based on the desired number of additional pixels
85
+ # for item in range(additional_pixels):
86
+ # convolution = signal.convolve2d(A, filter, mode='same')
87
+ # A = np.where(convolution <= 1, convolution, 1)
88
+ # return A
89
+
90
+
91
+ def add_pixels(array_original, thickness):
92
  A = array_original
93
+ # if thickness !=0:
94
+
95
+ # filter = np.array(([0, 1, 0], [1, 1, 1], [0, 1, 0]))
96
+ # filter = np.stack([filter] * additional_pixels, axis=-1)
97
+ filter_size = 2*thickness+1
98
+ filter = np.zeros((filter_size,filter_size))
99
+ filter[np.floor((filter_size - 1) / 2).astype(int), :] = filter[:, np.floor((filter_size - 1) / 2).astype(int)] =1
100
+ filter[np.ceil((filter_size - 1) / 2).astype(int), :] = filter[:, np.ceil((filter_size - 1) / 2).astype(int)] = 1
101
+
102
+ # filter[0,0] = filter[-1,0] = filter[0,-1] = filter[-1,-1] = 0
103
+ print(filter)
104
+ convolution = signal.convolve2d(A, filter, mode='same')
105
+ A = np.where(convolution <= 1, convolution, 1)
106
+ return A
107
+
108
+
109
+ # def create_array(basic_box_thickness, forward_slash_thickness, back_slash_thickness, hamburger_thickness, hot_dog_thickness):
110
+ #
111
+
112
+ # TESTING
113
+ image_size = 9
114
+ # test = forward_slash_array(image_size)
115
+ test = hamburger_array((image_size))
116
+ back = back_slash_array((image_size))
117
+ hot = hot_dog_array(image_size)
118
+ forward = forward_slash_array(image_size)
119
+ basic = basic_box_array((image_size))
120
+
121
+ # test = update_array(test, back)
122
+ # test = update_array(test, hot)
123
+ # test = update_array(test, forward)
124
+ test = test + back + forward + hot + basic
125
+ test = np.array(test > 0, dtype=int)
126
+
127
+ # test = add_pixels(test, 1)
128
+ print(test)
129
+ plt.imshow(test)
130
+ plt.show()
131
+
132
+
133
+ # basic_box_thickness = np.linspace(0,14, num=15)
134
+ # print(basic_box_thickness)
135
+ # forward_slash_thickness = np.linspace(0,14, num=15)
136
+ # back_slash_thickness = np.linspace(0,14, num=15)
137
+ # hamburger_thickness = np.linspace(0,14, num=15)
138
+ # hot_dog_thickness =np.linspace(0,14, num=15)
139
+ # print(np.meshgrid((basic_box_thickness, forward_slash_thickness, back_slash_thickness, hamburger_thickness, hot_dog_thickness)))
140
+
141
+ # all_thicknesses = list(itertools.product(basic_box_thickness, repeat=5))
142
+ # print(all_thicknesses)
143
+ # print(np.shape(all_thicknesses))