import numpy as np | |
from scipy import signal | |
import math | |
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, image_size): | |
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 |