marta-marta commited on
Commit
822d985
·
1 Parent(s): 60acf32

Optimizing functions to produce dataset with large image sizes

Browse files
Data_Generation/Piecewise_Box_Functions.py CHANGED
@@ -1,4 +1,5 @@
1
  import numpy as np
 
2
  import math
3
 
4
 
@@ -77,12 +78,11 @@ def update_array(array_original, array_new, image_size):
77
  def add_pixels(array_original, additional_pixels, image_size):
78
  # Adds pixels to the thickness of each component of the box
79
  A = array_original
80
- A_updated = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
81
- for dens in range(additional_pixels):
82
- for i in range(1, image_size - 1):
83
- for j in range(1, image_size - 1):
84
- if A[i - 1][j] + A[i + 1][j] + A[i][j - 1] + A[i][j + 1] > 0:
85
- A_updated[i][j] = 1
86
- A = update_array(A, A_updated,image_size)
87
- return A
88
-
 
1
  import numpy as np
2
+ from scipy import signal
3
  import math
4
 
5
 
 
78
  def add_pixels(array_original, additional_pixels, image_size):
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