File size: 2,825 Bytes
60acf32 822d985 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 5b65c9e 60acf32 9c41b55 5b65c9e 60acf32 5b65c9e 9e671c6 78a2f2b 9c41b55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import numpy as np
from scipy import signal
def basic_box_array(image_size, thickness):
A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
A[1:-1, 1:-1] = 0 # replaces all internal rows/columns with 0's
A = add_thickness(A, thickness)
return A
def back_slash_array(image_size, thickness):
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
np.fill_diagonal(A, 1) # fills the diagonal with 1 values
A = add_thickness(A, thickness)
return A
def forward_slash_array(image_size, thickness):
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
np.fill_diagonal(np.fliplr(A), 1) # Flips the array to then fill the diagonal the opposite direction
A = add_thickness(A, thickness)
return A
def hot_dog_array(image_size, thickness):
# Places pixels down the vertical axis to split the box
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
A[:, np.floor((image_size - 1) / 2).astype(int)] = 1 # accounts for even and odd values of image_size
A[:, np.ceil((image_size - 1) / 2).astype(int)] = 1
A = add_thickness(A, thickness)
return A
def hamburger_array(image_size, thickness):
# Places pixels across the horizontal axis to split the box
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
A[np.floor((image_size - 1) / 2).astype(int), :] = 1 # accounts for even and odd values of image_size
A[np.ceil((image_size - 1) / 2).astype(int), :] = 1
A = add_thickness(A, thickness)
return A
########################################################################################################################
# The function to add thickness to struts in an array
def add_thickness(array_original, thickness):
A = array_original
if thickness == 0: # want an array of all 0's for thickness = 0
A[A > 0] = 0
else:
filter_size = 2*thickness - 1 # the size of the filter needs to extend far enough to reach the base shape
filter = np.zeros((filter_size, filter_size))
filter[np.floor((filter_size - 1) / 2).astype(int), :] = filter[:, np.floor((filter_size - 1) / 2).astype(int)] =1
filter[np.ceil((filter_size - 1) / 2).astype(int), :] = filter[:, np.ceil((filter_size - 1) / 2).astype(int)] = 1
convolution = signal.convolve2d(A, filter, mode='same')
A = np.where(convolution <= 1, convolution, 1)
return A
# The function to efficiently combine arrays in a list
def combine_arrays(arrays):
output_array = np.sum(arrays, axis=0) # Add the list of arrays
output_array = np.array(output_array > 0, dtype=int) # Convert all values in array to 1
return output_array
|