-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryArray.py
More file actions
87 lines (60 loc) · 2.33 KB
/
binaryArray.py
File metadata and controls
87 lines (60 loc) · 2.33 KB
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
# -*- coding: utf-8 -*-
"""
A method to create a "false" binary array and convert a section of it to "true"
Plot output to visualise
@author: michael@eilonal.uk
versions of libraries
---------------------
numpy 1.20.3
Pillow 8.2.0
Spyder Editor
"""
import numpy as np
from PIL import Image
class binaryArray:
def __init__(self, rows, cols, top_left, bottom_right):
self.rows = rows
self.cols = cols
self.x1 = top_left[0]
self.x2 = bottom_right[0]
self.y1 = top_left[1]
self.y2 = bottom_right[1]
def image_array(self):
array = np.zeros((self.rows, self.cols), dtype='bool')
array[self.x1:self.x2,self.y1:self.y2] = True
#print('self.....',self.x1, self.x2, self.y1, self.y2)
#print(type(self.x1))
# tests of input
error_out = []
if self.x1 < 0 or self.x2 < 0 or self.y1 < 0 or self.y2 < 0:
error_out = 'Value Error---- top left or bottom right cannot extend outside array'
return array, error_out
def input_data():
array_input = input("enter number of rows and columns (seperated by ,):......")
array_input = array_input.split(',')
rows = int(array_input[0])
cols = int(array_input[1])
top_left_input = input("top left corner of box (seperated by ,):......")
top_left_input = top_left_input.split(',')
top_left = [int(top_left_input[0]), int(top_left_input[1])]
bottom_right_input = input("bottom right corner of box (seperated by ,):......")
bottom_right_input = bottom_right_input.split(',')
bottom_right = [int(bottom_right_input[0]), int(bottom_right_input[1])]
return rows, cols, top_left, bottom_right
def main():
rows, cols, top_left, bottom_right = input_data()
test_out = binaryArray(rows, cols, top_left, bottom_right)
array_out, error_out = test_out.image_array()
if error_out:
print(error_out)
image = Image.fromarray(array_out)
image.show()
if __name__ == '__main__':
main()
#------------------------------------------------------------
__author__ = "Michael Robinson"
__copyright__ = "Copyright 2021, M Robinson"
__license__ = "GPL"
__version__ = "0.0.1"
__maintainer__ = "M Robinson"
__status__ = "Prototype"