1 import Image, ImageDraw
2 import math
3
4 def yuv2rgb(Y,U,V):
5 R = 1.164*(Y - 16) + 1.596*(V - 128)
6 G = 1.164*(Y - 16) - 0.813*(V - 128) - 0.391*(U - 128)
7 B = 1.164*(Y - 16) + 2.018*(U - 128)
8 return tuple(map(int, (R,G,B)))
9
10 def rgb2yuv(R,G,B):
11 Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
12 U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
13 V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
14 return tuple(map(int, (Y,U,V)))
15
16 def evalue2rgb(evalue):
17 n = -math.log(evalue)/math.log(10)
18 if n > 70:
19 v = 255
20 elif n < 5:
21 v = 0
22 else:
23 v = int((n-5)*255/65)
24 print evalue, n, v
25 return yuv2rgb(10,50,v)
26
27 def makeSampleImage():
28 img = Image.new('RGB', (80,140), (255,255,255))
29 draw = ImageDraw.Draw(img)
30 for yline in range(128):
31 color = yuv2rgb(10, 50, 255-yline*2)
32 draw.line((5, yline+5, 35, yline+5), fill=color)
33 draw.text((40, 2), '1e-70', fill='black')
34 draw.text((40, 60), '1e-32', fill='black')
35 draw.text((40, 126), '1e-5', fill='black')
36 img.save('test.png',type='PNG')
37
38 def makeEvalueDistribution():
39 img = Image.new('RGB', (80,140), (255,255,255))
40 draw = ImageDraw.Draw(img)
41 y = 10
42 for evalue in (1e-3, 1e-5, 1e-10, 1e-34, 1e-68, 1e-70, 1e-80):
43 draw.rectangle((50, y, 70, y+10),fill=evalue2rgb(evalue))
44 y+=15
45 img.save('test.png',type='PNG')
46
47 if __name__=='__main__':
48
49 makeEvalueDistribution()