File size: 5,112 Bytes
60acf32 822d985 60acf32 9e671c6 60acf32 9e671c6 60acf32 9e671c6 60acf32 9e671c6 |
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 |
import numpy as np
from scipy import signal
import math
import matplotlib.pyplot as plt
import itertools
def basic_box_array(image_size):
A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
# Creates the outside edges of the box
# for i in range(image_size):
# for j in range(image_size):
# if i == 0 or j == 0 or i == image_size - 1 or j == image_size - 1:
# A[i][j] = 1
# A[1:-1, 1:-1] = 1
# np.pad(A[1:-1,1:-1], pad_width=((1, 1), (1, 1)), mode='constant', constant_values=1)
A[1:-1, 1:-1] = 0
return A
def back_slash_array(image_size):
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
# for i in range(image_size):
# for j in range(image_size):
# if i == j:
# A[i][j] = 1
np.fill_diagonal(A, 1)
return A
def forward_slash_array(image_size):
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
# for i in range(image_size):
# for j in range(image_size):
# if i == (image_size-1)-j:
# A[i][j] = 1
np.fill_diagonal(np.fliplr(A), 1)
return A
def hot_dog_array(image_size):
# 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
# for i in range(image_size):
# for j in range(image_size):
# if j == math.floor((image_size - 1) / 2) or j == math.ceil((image_size - 1) / 2):
# A[i][j] = 1
A[:, np.floor((image_size - 1) / 2).astype(int)] = 1
A[:, np.ceil((image_size - 1) / 2).astype(int)] = 1
return A
def hamburger_array(image_size):
# 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
# for i in range(image_size):
# for j in range(image_size):
# if i == math.floor((image_size - 1) / 2) or i == math.ceil((image_size - 1) / 2):
# A[i][j] = 1
A[np.floor((image_size - 1) / 2).astype(int), :] = 1
A[np.ceil((image_size - 1) / 2).astype(int), :] = 1
return A
# def update_array(array_original, array_new, image_size):
# A = array_original
# for i in range(image_size):
# for j in range(image_size):
# if array_new[i][j] == 1:
# A[i][j] = 1
# return A
def update_array(array_original, array_new):
A = array_original
A[array_new == 1] = 1
return A
# def add_pixels(array_original, additional_pixels):
# # Adds pixels to the thickness of each component of the box
# A = array_original
# filter = np.array(([0, 1, 0], [1, 1, 1], [0, 1, 0])) # This filter will only add value where there are pixels on
# # the top, bottom, left or right of a pixel
#
# # This filter adds thickness based on the desired number of additional pixels
# for item in range(additional_pixels):
# convolution = signal.convolve2d(A, filter, mode='same')
# A = np.where(convolution <= 1, convolution, 1)
# return A
def add_pixels(array_original, thickness):
A = array_original
# if thickness !=0:
# filter = np.array(([0, 1, 0], [1, 1, 1], [0, 1, 0]))
# filter = np.stack([filter] * additional_pixels, axis=-1)
filter_size = 2*thickness+1
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
# filter[0,0] = filter[-1,0] = filter[0,-1] = filter[-1,-1] = 0
print(filter)
convolution = signal.convolve2d(A, filter, mode='same')
A = np.where(convolution <= 1, convolution, 1)
return A
# def create_array(basic_box_thickness, forward_slash_thickness, back_slash_thickness, hamburger_thickness, hot_dog_thickness):
#
# TESTING
image_size = 9
# test = forward_slash_array(image_size)
test = hamburger_array((image_size))
back = back_slash_array((image_size))
hot = hot_dog_array(image_size)
forward = forward_slash_array(image_size)
basic = basic_box_array((image_size))
# test = update_array(test, back)
# test = update_array(test, hot)
# test = update_array(test, forward)
test = test + back + forward + hot + basic
test = np.array(test > 0, dtype=int)
# test = add_pixels(test, 1)
print(test)
plt.imshow(test)
plt.show()
# basic_box_thickness = np.linspace(0,14, num=15)
# print(basic_box_thickness)
# forward_slash_thickness = np.linspace(0,14, num=15)
# back_slash_thickness = np.linspace(0,14, num=15)
# hamburger_thickness = np.linspace(0,14, num=15)
# hot_dog_thickness =np.linspace(0,14, num=15)
# print(np.meshgrid((basic_box_thickness, forward_slash_thickness, back_slash_thickness, hamburger_thickness, hot_dog_thickness)))
# all_thicknesses = list(itertools.product(basic_box_thickness, repeat=5))
# print(all_thicknesses)
# print(np.shape(all_thicknesses)) |