Skip to content

Commit fc1728d

Browse files
committed
Improve images readability
1 parent 382123d commit fc1728d

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed
Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from colr import color
2+
import numpy as np
23

34
from eggdriver.resources.structures.lists import List
45
from eggdriver.resources.structures.matrices import listMatrix
56
from eggdriver.resources.modules import installFromRequests
67
from eggdriver.resources.console import sleep
7-
from eggdriver.resources.constants import limit, square, whiteSquare, blackSquare
8+
from eggdriver.resources.constants import limit, square #, whiteSquare, blackSquare
89

910
class Image(listMatrix):
11+
1012
def __init__(self, listOfLists = [], auto_install = True):
1113
super().__init__(listOfLists)
1214
self.bias = [0, 0, 0]
@@ -16,49 +18,68 @@ def __init__(self, listOfLists = [], auto_install = True):
1618

1719
def load(self, fileName):
1820
from keras.preprocessing import image # Local import
19-
import numpy as np # Local import
21+
2022
source = image.img_to_array(image.load_img(fileName)) # Matrix with elements of form [224. 228. 255.]
2123
for i in np.array(source):
2224
self.addLast(List(i))
25+
2326
def save(self, fileName):
2427
from keras.preprocessing import image # Local import
25-
from PIL import Image
26-
import numpy as np
28+
from PIL import Image # Required
29+
2730
pil_img = image.array_to_img(self.matrix)
2831
pil_img.save(fileName)
32+
2933
def loadFromBW(self, vanillaMatrix):
34+
3035
for vanillaList in vanillaMatrix:
36+
3137
list = List([])
3238
for i in vanillaList:
3339
item = [i, i, i]
3440
list.addLast(item)
41+
3542
self.addLast(list)
43+
3644
def loadFromRGB(self, vanillaMatrix):
3745
[self.addLast(List(vanillaList)) for vanillaList in vanillaMatrix]
38-
def printRGB(self):
46+
47+
def printRGB(self, delay = 10):
3948
b = self.bias
49+
4050
for vanillaList in self.matrix:
51+
4152
line = limit
4253
for j in vanillaList:
4354
line += color(square, fore=(self.colour(j, 0), self.colour(j, 1), self.colour(j, 2)), back=(0, 0, 0))
55+
4456
print(line + limit)
45-
sleep(10)
57+
58+
sleep(delay)
4659
print("")
47-
def printBW(self):
48-
from colr import color # Local import
60+
61+
def printBW(self, delay = 10):
62+
4963
for vanillaList in self.matrix:
64+
5065
line = limit
5166
for j in vanillaList:
5267
average = int((j[0] + j[1] + j[2]) / 3)
5368
line += color(square, fore=(average, average, average), back=(0, 0, 0))
69+
5470
print(line + limit)
55-
sleep(10)
71+
72+
sleep(delay)
5673
print("")
74+
5775
def colour(self, list, id):
5876
b = self.bias[id]
5977
result = b + list[id]
78+
6079
if result < 0:
6180
return 0
81+
6282
if result > 255:
6383
return 255
84+
6485
return result

0 commit comments

Comments
 (0)