-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageAnalysis.py
More file actions
127 lines (94 loc) · 3.03 KB
/
Copy pathImageAnalysis.py
File metadata and controls
127 lines (94 loc) · 3.03 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
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
import subprocess
import string
import numpy as np
import time
import tarfile as tar
import ImageTool as imgtl
import matplotlib.pyplot as plt
import sys
from scipy import ndimage
import pylab as pyl
cmdargs = str(sys.argv)
# defaults values
Num = 1
srv = 1
cal = 1.0
if len(sys.argv)<2:
print("Error: usage is python ImageAnalysis.py $filename [$background] ...")
print(" where [$background] is optional but highly recommended...")
sys.exit()
if len(sys.argv)==2:
filenameIm = sys.argv[1]
print("filename/rootnames: "+filenameIm)
X = pyl.imread(filenameIm)
if len(sys.argv)==3:
filenameIm = sys.argv[1]
print("image file: "+filenameIm)
filenameBk = sys.argv[2]
print("background file: "+filenameBk)
Xi = pyl.imread(filenameIm)
Xb = pyl.imread(filenameBk)
X=Xi-Xb
Xc=imgtl.RemoveEdge(X, 0)
plt.imshow(Xc)
norm0, meanx0, meany0, meanI0, stdx0, stdy0, stdI0, correl0, Wx0, Wy0, averImage0, IMGf = \
imgtl.window_scan2dthreshold(Xc, 1., 50, 0.00)
plt.figure()
plt.subplot (2,2,1)
plt.plot (Wx0, averImage0,'o')
plt.subplot (2,2,2)
plt.plot (Wx0, stdx0,'ro')
plt.plot (Wx0, stdy0,'go')
plt.subplot (2,2,3)
plt.plot (Wx0, correl0,'ro')
plt.subplot (2,2,4)
plt.plot (Wx0, norm0,'ro')
plt.figure()
plt.imshow(Xc)
print(np.shape(IMGf))
histx, histy, x, y = imgtl.GetImageProjection(IMGf,cal)
x=x-x[np.argmax(histx)]
y=y-y[np.argmax(histy)]
p2X= imgtl.FitProfile(histx, x)
p2Y= imgtl.FitProfile(histy, y)
print('RMS_x=',np.mean(stdx0[len(stdx0)-2:len(stdx0)+2]))
print('RMS_y=',np.mean(stdy0[len(stdy0)-2:len(stdy0)+2]))
print("fitX: ", p2X)
print("fitY: ", p2Y)
plt.figure()
disp=filenameIm.split('/')
print(disp)
print(len(disp))
plt.subplot (2,2,1)
plt.title (disp[len(disp)-1])
plt.imshow(ndimage.gaussian_filter(IMGf, 10), extent=[min(x), max(x), min(y), max(y)], \
aspect='auto', cmap='coolwarm')
plt.subplot (2,2,3)
plt.plot (x, histx)
plt.plot (x, imgtl.dg(x,p2X),'--',linewidth=3)
plt.xlim(min(x), max(x))
plt.subplot (2,2,2)
plt.plot (histy,y)
plt.plot (imgtl.dg(y,p2Y),y,'--',linewidth=3)
plt.ylim(min(y), max(y))
plt.subplot (2,2,4)
plt.ylim(0,10)
plt.xlim(0,10)
text1='rms_x = '+str('{0:.2f}'.format((np.mean(stdx0[len(stdx0)-2:len(stdx0)+2])))) \
+'+/-'+str('{0:.2f}'.format(np.std(stdx0[len(stdx0)-2:len(stdx0)+2])))
text2='rms_y = '+str('{0:.2f}'.format((np.mean(stdy0[len(stdy0)-2:len(stdy0)+2])))) \
+'+/-'+str('{0:.2f}'.format(np.std(stdy0[len(stdy0)-2:len(stdy0)+2])))
text3='<xy>/(rms_x*rms_y) = '+str('{0:.2f}'.format((np.mean(correl0[len(correl0)-2:len(correl0)+2])))) \
+'+/-'+str('{0:.2f}'.format(np.std(correl0[len(correl0)-2:len(correl0)+2])))
text4='sig_x = '+str('{0:.2f}'.format((np.mean(p2X[2]))))
text5='sig_y = '+str('{0:.2f}'.format((np.mean(p2Y[2]))))
plt.text (2,9,'statistical analysis')
plt.text (0.5,8,text1)
plt.text (0.5,7,text2)
plt.text (0.5,6,text3)
plt.text (2,4,'Gaussian fit')
plt.text (0.5,3,text4)
plt.text (0.5,2,text5)
plt.text (0.5,1,'units are pixels')
plt.axis('off')
plt.show()