-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
149 lines (100 loc) · 3.42 KB
/
draw.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Author: Eleftherios Garyfallidis & Ian Nimmo-Smith
Info:
2d image, 2d plotting, camera and 3d plotting through mayavi.mlab
Example:
x=sp.rand(30), pylab.plot(x), pylab.hist(x),
pylab.imshow(255*sp.rand(40,40)), pylab.show()
'''
try:
#import matplotlib
from matplotlib import pyplot, mpl
except:
print('matplotlib is not installed.')
try:
import PIL
except:
print('PIL is not installed.')
try:
import opencv
except:
print('Opencv is not installed')
try:
from enthought.mayavi.mlab import *
except:
print('Mayavi is not installed')
import form
import scipy as sp
def testinterp():
xp = [1, 2, 3]
fp = [3, 2, 0]
sp.interp(2.5, xp, fp)
sp.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)
UNDEF = -99.0
sp.interp(3.14, xp, fp, right=UNDEF)
#Plot an interpolant to the sine function:
x = sp.linspace(0, 2*sp.pi, 10)
y = sp.sin(x)
xvals = sp.linspace(0, 2*sp.pi, 50)
yinterp = sp.interp(xvals, x, y)
pyplot.plot(x, y, 'o')
pyplot.plot(xvals, yinterp, '-x')
pyplot.show()
def testhist():
fname='/home/eg309/Data/AquaTermi_lowcontrast.JPG'
#fname='/home/eg01/Data/AquaTermi_lowcontrast.JPG'
#imhist,bins = sp.histogram(im.flatten(),nbr_bins,normed=True,new=True)
im=form.loadpic(fname)
print im.shape
nbr_bins=256
#Return the hist
imhist,bins = sp.histogram(im.flatten(),nbr_bins,normed=True,new=True)
#pylab.hist(im.flatten(),nbr_bins,normed=True,new=True)
pyplot.figure(1)
print 'imhist',imhist.shape
pyplot.plot(imhist)
pyplot.figure(2)
#fig.add_subplot(2,1,1)
pyplot.imshow(im, cmap=mpl.cm.gray)
pyplot.show()
pyplot.figure(3)
cdf = imhist.cumsum() #cumulative distribution function
cdf = 255 * cdf / cdf[-1] #normalize
print 'bins.shape',bins.shape
print 'cdf.shape',cdf.shape
#use linear interpolation of cdf to find new pixel values
im2 = sp.interp(im.flatten(),bins[10:-1],cdf[10:])
print 'im.min',im.min()
print 'im.max',im.max()
print 'im.min',im2.min()
print 'im.max',im2.max()
pyplot.imshow(im2.reshape(im.shape), cmap=mpl.cm.gray)
pyplot.show()
def testsubplot():
print 'Test'
pyplot.figure(1) # the first figure
pyplot.subplot(211) # the first subplot in the first figure
pyplot.plot([1,2,3])
pyplot.subplot(212) # the second subplot in the first figure
pyplot.plot([4,5,6])
pyplot.figure(2) # a second figure
pyplot.plot([4,5,6]) # creates a subplot(111) by default
pyplot.figure(1) # figure 1 current; subplot(212) still current
pyplot.subplot(211) # make subplot(211) in figure1 current
pyplot.title('Easy as 1,2,3') # subplot 211 title
def animationexample():
from pylab import *
import time
ion()
tstart = time.time() # for profiling
x = arange(0,2*pi,0.01) # x-array
line, = plot(x,sin(x))
for i in arange(1,200):
line.set_ydata(sin(x+i/10.0)) # update the data
draw() # redraw the canvas
print 'FPS:' , 200/(time.time()-tstart)
if __name__ == "__main__":
testhist()
#testsubplot()