In [1]:
import os
In [2]:
import numpy as np
In [3]:
path='/home/sophie/Desktop/10007ss2/'
In [4]:
for fn in os.listdir(path):
fn2=fn.split('-')
fnnum=fn2[1].split('_')
i=int(fnnum[0])
fnnew=fn2[0]+'-'+ str(i).zfill(5) + '_'+fnnum[1]
os.rename(path+"/"+fn, path+"/"+fnnew)
In [4]:
data = tsc.loadImages(path, inputFormat='tif')
In [5]:
data.dims
Out[5]:
In [6]:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('notebook')
from thunder import Colorize
image = Colorize.image
Open an example image in the middle of the time series
In [7]:
N = int(data.nrecords/2)
In [8]:
N
Out[8]:
In [9]:
imgN = tsc.loadImages(path, inputFormat='tif', startIdx=N, stopIdx=N+1)
In [10]:
img=thunder.Images.collectValuesAsArray(imgN)
In [11]:
img.shape
Out[11]:
In [13]:
image(img[0,:,:,20])
Click on the example image to extract cropping window
In [14]:
import Tkinter
import PIL
from PIL import Image, ImageTk, ImageOps
from sys import argv
import numpy as np
In [15]:
window = Tkinter.Tk(className="bla")
In [16]:
img2=np.mean(img,3)
In [17]:
img2=np.squeeze(img2*255/np.max(img2))
In [18]:
img2.shape
Out[18]:
In [19]:
imgim=Image.fromarray(img2)
In [20]:
print imgim.format, imgim.size, imgim.mode
In [21]:
imgim=imgim.convert('L')
In [22]:
imgim=ImageOps.autocontrast(imgim)
In [23]:
canvas = Tkinter.Canvas(window, width=img2.shape[1], height=img2.shape[0])
In [24]:
canvas.pack()
In [25]:
image_tk = ImageTk.PhotoImage(imgim)
In [26]:
canvas.create_image(img2.shape[1]/2, img2.shape[0]/2, image=image_tk)
Out[26]:
In [27]:
Pcrop=[0,0,0,0]
In [28]:
def callback(event):
global Pcrop
if (Pcrop[1]==0):
Pcrop[0] = event.x
Pcrop[1] = event.y
else:
Pcrop[2] = event.x
Pcrop[3] = event.y
print "clicked at: ", event.x, event.y
def quit(root):
root.destroy()
root = Tkinter.Tk()
canvas.bind("<Button-1>", callback)
Tkinter.Button(root, text="Q", command=lambda root=root:quit(root)).pack()
root.mainloop()
In [207]:
Pcrop
Out[207]:
Crop Images
In [238]:
S=img.shape
In [239]:
S
Out[239]:
In [8]:
datac=data.crop((Pcrop[1],Pcrop[0],0),(Pcrop[3],Pcrop[2],S[3]))
In [241]:
datac.dims
Out[241]:
In [242]:
mg = datac[N]
In [243]:
mg.shape
Out[243]:
In [244]:
from thunder import Colorize
image = Colorize.image
In [245]:
image(mg[:,:,20])
In [7]:
D=thunder.Images.collectValuesAsArray(data)
In [8]:
S=D.shape
In [9]:
S
Out[9]:
In [10]:
M=np.mean(np.mean(np.mean(D,1),1),1)
In [11]:
plt.plot(np.squeeze(M))
plt.show()
In [12]:
Mav=M.mean()
In [13]:
liston=[i for i in range(len(M)) if M[i]>Mav*0.7]
In [14]:
liston2=[liston[i] for i in range(1,(len(liston)-1))]
In [15]:
len(liston)
Out[15]:
In [16]:
from nifti import NiftiImage
In [17]:
D2=D[liston2[:],:,:,:]
In [18]:
D2.shape
Out[18]:
In [19]:
D3=np.transpose(D2,(0,3,1,2))
In [20]:
nim = NiftiImage(D3)
In [21]:
D3.shape
Out[21]:
In [22]:
print nim.header['dim']
In [23]:
nim.save('/home/sophie/Desktop/10007ss2.nii.gz')
In [ ]: