In [1]:
import numpy as np
from nifti import NiftiImage
In [2]:
# from http://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
In [3]:
nim=NiftiImage(filename)
In [4]:
D=nim.data
D.shape
Out[4]:
In [5]:
#np.save('863try500regc.npy',D)
In [6]:
#Dts=tsc.loadSeries('/home/sophie/Desktop/862try500regcU.npy', inputFormat='npy')
In [7]:
from thunder.rdds.fileio.imagesloader import ImagesLoader
imgs = ImagesLoader(sc).fromArrays(list(D))
In [9]:
S=imgs.toTimeSeries()
In [ ]:
Smean=S.seriesMean().collect()
In [ ]:
Smean.shape
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('notebook')
from thunder import Colorize
image = Colorize.image
In [ ]:
from pylab import *
from scipy.optimize import curve_fit
In [ ]:
def func(x, a, b, c, d, e):
return a*(1+b*np.exp(-c*x)+d*np.exp(-e*x))
In [ ]:
def func2(x, a):
return a
In [ ]:
def Debleach(x):
X=range(len(x))
#try:
popt, pcov = curve_fit(func, X, x,[0.02,0.0556,0.02677,0.0529,0.002028],maxfev=15000)
[a, b, c, d, e]=popt
y=[x[i]-a*(1+b*np.exp(-c*i)+d*np.exp(-e*i)) for i in X]
# except Exception:
# popt, pcov = curve_fit(func2, X, x,[0.02,0.0556,0.02677,0.0529,0.002028],maxfev=15000)
# [a]=popt
# y=[x[i]-a for i in X]
return y
'StartPoint',[1,0.0556,0.01377,0.1629,0.001028],'Lower',[0.001,0.01,0.002,0.01,0],'Upper',[10,0.6,0.1,0.6,0.002]
In [ ]:
xd=Debleach(Smean)
In [65]:
plt.plot(xd)
Out[65]:
In [19]:
Dd=S.rdd.mapValues(Debleach)
In [ ]:
S.rdd=Dd
In [67]:
Dd.count()
Out[67]:
In [21]:
Dd[1:3].shape
In [ ]:
nim2.data=S.
In [8]:
from thunder import Registration
reg=Registration('crosscorr')
reg.prepare(imgs,startIdx=100,stopIdx=150)
In [ ]:
model=reg.fit(imgs)
imreg=model.transform(imgs)