-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProcessing.py
55 lines (48 loc) · 1.79 KB
/
ImageProcessing.py
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
from PIL import Image
import numpy as np
from JsonProcessing import JsonProcessing
from random import randint
import time
from JsonProcessing import JsonProcessing
class ImageProcessing(object):
"""docstring for ImageProcessing."""
def __init__(self, jp, colors, genosToShow=None):
super(ImageProcessing, self).__init__()
self.jp = jp
assert jp, JsonProcessing()
assert (jp.isInitialized() == True)
self.genosToShow = genosToShow
self.colors = colors
def displayImage(self):
# TODO
width = 700
height = 700
channels = 3
genodict, genoKeys = self.jp.getOrderedGenotypeKeyDict()
self.genoList = self.jp.getOrderedGenotypeList(genodict, genoKeys)
# Set the RGB values
print("Processing...")
img = self.getImage(height, width, channels, self.genosToShow)
img.show()
#TODO
print("Genotype {} save...".format("all"))
print("Done.")
def getImage(self, height, width, channels, geno=None):
position = 0
img = np.zeros((height, width, channels), dtype=np.uint8)
for y in range(img.shape[0]):
for x in range(img.shape[1]):
position += 1
r, g, b = self.getColors(x, y, position, geno)
img[y][x][0] = r
img[y][x][1] = g
img[y][x][2] = b
img = Image.fromarray(img)
return img
def getColors(self, x, y, position, targetGeno=None):
geno = self.genoList[position]
if(targetGeno):
if (geno in targetGeno):
return self.colors[geno]["r"], self.colors[geno]["g"], self.colors[geno]["b"]
return 0, 0 ,0
return self.colors[geno]["r"], self.colors[geno]["g"], self.colors[geno]["b"]