File size: 9,245 Bytes
60acf32 07b21c4 9f580f1 07b21c4 9f580f1 07b21c4 9f580f1 60acf32 07b21c4 60acf32 07b21c4 9f580f1 60acf32 07b21c4 9f580f1 07b21c4 60acf32 07b21c4 60acf32 9f580f1 07b21c4 9f580f1 07b21c4 60acf32 07b21c4 9f580f1 60acf32 07b21c4 9f580f1 |
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
import numpy as np
# from Data_Generation.Shape_Generation_Functions import basic_box, diagonal_box_split, horizontal_vertical_box_split, \
# back_slash_box, forward_slash_box, back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, \
# x_hamburger_box, x_hot_dog_box, x_plus_box
from Piecewise_Box_Functions import basic_box_array, back_slash_array, forward_slash_array, hamburger_array, hot_dog_array
import matplotlib.pyplot as plt
########################################################################################################################
# Make the data using all the code in Shape_Generation_Functions.py
def make_boxes(image_size, densities):
"""
:param image_size: [int] - the pixel height and width of the generated arrays
:param densities: [list] - of the values of each of the active pixels in each shape
:param shapes: [list] - of the various shapes desired for the dataset
:return: [list[tuple]] - [Array, Density, Thickness, Shape]
"""
matrix = []
#
# for function in shapes: # Adds different types of shapes
#
# # Adds different density values
# for i in range(len(densities)):
# # Loops through the possible thickness values
# for j in range(image_size): # Adds additional Pixels
# thickness = j
# Array = (function(thickness, densities[i], image_size))
#
# # Checks if there are any 0's left in the array to append
# if (np.where((Array == float(0)))[0] > 0).any():
# the_tuple = (Array, str(function.__name__), densities[i], thickness)
# matrix.append(the_tuple)
#
# # Prevents solids shapes from being appended to the array
# else:
# break
# Establish the maximum thickness for each type of strut
max_vert = int(np.ceil(1 / 2 * image_size) - 2)
max_diag = int(image_size - 3)
max_basic = int(np.ceil(1 / 2 * image_size) - 1)
# Adds different density values
for i in range(len(densities)):
for j in range(1, max_basic): # basic box loop, always want a border
basic_box_thickness = j
array_1 = basic_box_array(image_size, basic_box_thickness)
if np.unique([array_1]).all() > 0: # Checks if there is a solid figure
break
for k in range(0, max_vert):
hamburger_box_thickness = k
array_2 = hamburger_array(image_size, hamburger_box_thickness) + array_1
array_2 =np.array(array_2 > 0, dtype=int) # Keep all values 0/1
if np.unique([array_2]).all() > 0:
break
for l in range(0, max_vert):
hot_dog_box_thickness = l
array_3 = hot_dog_array(image_size, hot_dog_box_thickness) + array_2
array_3 = np.array(array_3 > 0, dtype=int)
if np.unique([array_3]).all() > 0:
break
for m in range(0, max_diag):
forward_slash_box_thickness = m
array_4 = forward_slash_array(image_size, forward_slash_box_thickness) + array_3
array_4 = np.array(array_4 > 0, dtype=int)
if np.unique([array_4]).all() > 0:
break
for n in range(0, max_diag):
back_slash_box_thickness = n
array_5 = back_slash_array(image_size, back_slash_box_thickness) + array_4
array_5 = np.array(array_5 > 0, dtype=int)
if np.unique([array_5]).all() > 0:
break
the_tuple = (array_5*densities[i], densities[i], basic_box_thickness,
forward_slash_box_thickness, back_slash_box_thickness,
hot_dog_box_thickness, hamburger_box_thickness)
matrix.append(the_tuple)
# matrix = []
# base_shapes = []
#
#
#
#
#
# density_1 = []
# for function in shapes: # Create an array of the base shapes
# thickness = 0
# Array = function(thickness, 1, image_size)
# # density_1_tuple = np.array([Array, str(function.__name__), 1, thickness]) # Array, Shape, Density, Thickness
# # base_shapes.append(density_1_tuple)
#
# density_1 = np.append(density_1,(np.array([Array, str(function.__name__), 1, thickness])), axis=1) # Array, Shape, Density, Thickness
# # Add one to the thickness of the previous array
# # for j in range(image_size):
# while (np.where((Array == float(0)))[0] > 0).any():
# # Checks if there are any 0's left in the array to append
# # if (np.where((Array == float(0)))[0] > 0).any():
# # density_1.append(density_1_tuple, axis=0)
# thickness += 1
# if np.shape(density_1) == (4,):
# Array = add_pixels(density_1[0], 1) # will add 1 pixel to each previous array, rather than adding multiple and having to loop
#
# else:
# print(np.shape(density_1))
# print(density_1[-1][0])
# Array = add_pixels(density_1[-1][0], 1)
# # print(np.shape(Array))
# density_1_tuple = np.array([Array, str(function.__name__), 1, thickness])
# # else: # Prevents solids shapes from being appended to the array
# # break
# density_1 = np.vstack((density_1, density_1_tuple))
#
# matrix = []
# # print(np.shape(density_1[0]))
# # print(density_1[:][0])
# for i in range(len(densities)):
# some = np.multiply(density_1[:][0],densities[i]) #,density_1[:1])
# # print(np.shape(some))
# matrix.append(tuple(some))
#
#
# # # Adds different density values
# # for i in range(len(densities)):
# # # Loops through the possible thickness values
# # for j in range(image_size): # Adds additional Pixels
# # thickness = j
# # Array = (function(thickness, densities[i], image_size))
# #
# # # Checks if there are any 0's left in the array to append
# # if (np.where((Array == float(0)))[0] > 0).any():
# # the_tuple = (Array, str(function.__name__), densities[i], thickness)
# # matrix.append(the_tuple)
# #
# # # Prevents solids shapes from being appended to the array
# # else:
# # break
return matrix
########################################################################################################################
# # Testing
# image_size = 9
# densities = [1]
# shapes = [basic_box, diagonal_box_split, horizontal_vertical_box_split, back_slash_box, forward_slash_box,
# back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, x_hamburger_box,
# x_hot_dog_box, x_plus_box]
#
# boxes = make_boxes(image_size, densities, shapes)
#
# # print(np.shape(boxes))
# desired_label = 'basic_box'
# desired_density = 1
# desired_thickness = 0
#
# box_arrays, box_shape, box_density, box_thickness, = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3]
# # print(np.shape(box_arrays))
# # print(np.shape(box_shape))
# # print(np.shape(box_density))
#
# indices = [i for i in range(len(box_arrays)) if box_shape[i] == desired_label and box_density[i] == desired_density and box_thickness[i] == desired_thickness]
# plt.imshow(box_arrays[indices[0]])
# plt.show()
########################################################################################################################
# Testing
image_size = 9
densities = [1]
boxes = make_boxes(image_size, densities)
desired_density = 1
# desired_thickness = 0
desired_basic_box_thickness =1
desired_forward_slash_box_thickness=2
desired_back_slash_box_thickness=0
desired_hot_dog_box_thickness=0
desired_hamburger_box_thickness=0
box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
= list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
# print(np.shape(box_arrays))
# print(np.shape(box_shape))
# print(np.shape(box_density))
indices = [i for i in range(len(box_arrays)) if box_density[i] == desired_density
and basic_box_thickness[i] == desired_basic_box_thickness
and forward_slash_box_thickness[i] == desired_forward_slash_box_thickness
and back_slash_box_thickness[i] == desired_back_slash_box_thickness
and hot_dog_box_thickness[i] == desired_hot_dog_box_thickness
and hamburger_box_thickness[i] == desired_hamburger_box_thickness]
plt.imshow(box_arrays[indices[0]])
plt.show()
|