In [36]:
import sys
sys.path.append('../code/functions')
sys.path.append('../../code/functions')
import numpy as np
import tiffIO as io
import neuroGraphLib as ngl
import matplotlib.pyplot as plt
from scipy import ndimage
from cluster import Cluster
from scipy.signal import convolve
from neuroGraphLib import neuroGraph
from skimage.exposure import equalize_adapthist
In [3]:
data = np.array(io.loadTiff('../data/rr46b_s1_ch1.tif'))
In [82]:
for i in range(0, data.shape[0], 5):
plt.figure()
plt.imshow(data[i], cmap='gray')
plt.title('Raw Data at z = '+str(i))
plt.show()
In [83]:
for i in range(0, data.shape[0], 5):
plt.figure()
plt.imshow(equalize_adapthist(data[i]), cmap='gray')
plt.title('Equalized Data at z = '+str(i))
plt.show()
In [84]:
plt.imshow(data[15, 100:400, 500:900], cmap='gray')
plt.show()
In [85]:
import connectLib as cLib
In [86]:
adaptiveOut = cLib.adaptiveThreshold(data, 64, 64)
In [87]:
for i in range(0, data.shape[0], 5):
plt.figure()
plt.imshow(adaptiveOut[i], cmap='gray')
plt.title('Adaptive Output at z = '+str(i))
plt.show()
In [88]:
plt.imshow(adaptiveOut[15, 100:400, 500:900], cmap='gray')
plt.show()
In [89]:
knnOut = cLib.knn_filter(adaptiveOut, 2)
In [90]:
for i in range(0, data.shape[0], 5):
plt.figure()
plt.imshow(knnOut[i], cmap='gray')
plt.title('Connected Components Output at z = '+str(i))
plt.show()
In [91]:
plt.imshow(knnOut[15, 100:400, 500:900], cmap='gray')
plt.show()
In [92]:
s = [[[1 for k in xrange(3)] for j in xrange(3)] for i in xrange(3)]
connectionImg, nr_objects = ndimage.label(knnOut, s)
In [93]:
synapseLists = cLib.clusterThresh(connectionImg, 5, 100)
In [94]:
clusterVis = np.zeros_like(data)
for synapse in synapseLists:
for member in synapse.members:
clusterVis[member[0]][member[1]][member[2]] = 1
for i in range(0, clusterVis.shape[0], 5):
plt.figure()
plt.imshow(clusterVis[i], cmap='gray')
plt.title('Cluster Visualization at Z = ' + str(i))
plt.show()
In [95]:
plt.imshow(clusterVis[15, 100:400, 500:900], cmap='gray')
plt.show()
In [4]:
dendriteImgStack = ngl.evolveDendrites(data, epochs=10, dilations=10)
In [12]:
for i in range(0, dendriteImgStack.shape[0], 5):
plt.figure()
plt.imshow(dendriteImgStack[i], cmap='gray')
plt.title('Dendrite Image at z= '+str(i))
plt.show()
In [30]:
plt.imshow(dendriteImgStack[15, 100:400, 500:900], cmap='gray')
plt.show()
In [8]:
nodeStack = np.stack([ngl.generateNodeImg(dendriteImg, 64) for dendriteImg in dendriteImgStack])
In [16]:
for i in range(0, nodeStack.shape[0], 5):
plt.figure()
nodeVis = np.zeros_like(nodeStack[i])
nodes = zip(*(np.nonzero(nodeStack[i])))
for node in nodes:
nodeVis[max(0, node[0]-3):min(1024, node[0]+3),
max(0, node[1]-3):min(1024, node[1]+3)] = 1
plt.imshow(nodeVis, cmap='gray')
plt.title('Node Visualization at z = '+ str(i))
plt.show()
In [22]:
neuroGraphStack = []
for idx, nodeImg in enumerate(nodeStack):
nodes, edges, vis = ngl.estimateGraph(nodeImg, dendriteImgStack[idx], neighbors = 10)
neuroGraphStack.append(neuroGraph(nodes, edges, vis))
In [23]:
for i in range(0, len(neuroGraphStack), 5):
plt.figure()
plt.imshow(neuroGraphStack[i]._vis)
plt.title('Neuro Graph At z = '+str(i))
plt.show()
In [28]:
synapseROIStack = []
for i in range(len(neuroGraphStack)):
synapseROIStack.append(ngl.getSynapseROIs(neuroGraphStack[i], data[i]))
In [29]:
roiImgStack = []
for synapseROIs in synapseROIStack:
curImg = np.zeros_like(data[0])
for y, x in synapseROIs:
curImg[y][x] = 1
roiImgStack.append(curImg)
for i in range(0, len(roiImgStack), 5):
plt.figure()
plt.imshow(roiImgStack[i], cmap='gray')
plt.title('Synapse ROIs at z = ' + str(i))
plt.show()
In [35]:
plt.imshow(roiImgStack[15][100:400, 500:900], cmap='gray')
plt.show()
In [60]:
def smoothROI(roiImg):
kernel_a = np.ones((8, 8))
kernel_b = np.ones((4, 4))
kernel_c = np.ones((2, 2))
roiSmooth = np.add(convolve(roiImg, kernel_a)[0:1024, 0:1024],
np.add(convolve(roiImg, kernel_b)[0:1024 ,0:1024],
convolve(roiImg, kernel_c)[0:1024, 0:1024]))
return roiSmooth
In [61]:
smoothROIStack = np.stack([smoothROI(roiImg) for roiImg in roiImgStack])
In [62]:
for i in range(0, len(smoothROIStack), 5):
plt.figure()
plt.imshow(smoothROIStack[i], cmap='gray')
plt.title('Smoothed Synapse ROIs at z = ' + str(i))
plt.show()
In [63]:
plt.imshow(smoothROIStack[15][100:400, 500:900], cmap='gray')
plt.show()
In [100]:
plt.figure()
plt.imshow(data[15, 100:400, 500:900], cmap='gray')
plt.title('Raw Data Zoom')
plt.show()
plt.figure()
plt.imshow(clusterVis[15, 100:400, 500:900], cmap='gray')
plt.title('Pipeline v1.0 Detections at Zoom')
plt.show()
plt.figure()
plt.imshow(smoothROIStack[15][100:400, 500:900], cmap='gray')
plt.title('Pipeline v2.0 Detections at Zoom')
plt.show()
In [ ]: