forked from omarocegueda/registration
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_ecqmmf.py
71 lines (63 loc) · 1.6 KB
/
test_ecqmmf.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
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 12 19:55:17 2013
@author: khayyam
"""
import nibabel as nib
import matplotlib.pyplot as plt
import ecqmmf
import numpy as np
#imageName='data/t1/t1_icbm_normal_1mm_pn0_rf0.rawb'
#ns=181
#nr=217
#nc=181
#image=np.fromfile(imageName, dtype=np.ubyte).reshape(ns,nr,nc)
#image=image.astype(np.float64)
#img=image[90,:,:].copy()
#MM=img.max()
#mm=img.min()
#img=(img-mm)/(MM-mm)
#image=nib.load('data/t1/IBSR18/IBSR_01/IBSR_01_ana_strip.nii.gz')
image=nib.load('data/t1/t1_icbm_normal_1mm_pn0_rf0_peeled.nii.gz')
image=image.get_data().squeeze()
image=image.astype(np.float64)
image=(image-image.min())/(image.max()-image.min())
sh=image.shape
img=image[:,sh[1]//2,:].copy()
nclasses=16
lambdaParam=.05
mu=.01
outerIter=20
innerIter=50
tolerance=1e-6
means, variances=ecqmmf.initialize_constant_models(img, nclasses)
means=np.array(means)
variances=np.array(variances)
segmented, means, variances, probs=ecqmmf.ecqmmf(img, nclasses, lambdaParam, mu, outerIter, innerIter, tolerance)
segmented=np.array(segmented)
means=np.array(means)
variances=np.array(variances)
probs=np.array(probs)
meanEstimator=probs.dot(means)
plt.figure()
plt.subplot(1,3,1)
plt.imshow(img)
plt.title('Input')
plt.subplot(1,3,2)
plt.imshow(segmented)
plt.title('Segmented')
plt.subplot(1,3,3)
plt.imshow(meanEstimator)
plt.title('Mean')
plt.figure()
side=np.floor((nclasses-1)**(0.5)).astype(int)+1
for i in range(nclasses):
plt.subplot(side,side,i+1)
plt.imshow(probs[:,:,i], cmap=plt.cm.gray)
plt.figure()
plt.subplot(1,2,1)
plt.plot(means)
plt.subplot(1,2,2)
plt.plot(variances)
print means
print variances