if __name__ == "__main__": # datadir = '../data' targnii = 'prob-face-object.nii.gz' masknii = 'prob-face-object.nii.gz' mask = nib.load(masknii) mask = mask.get_data() # ds = bpfmri_dataset(pjoin(datadir,targnii)) ds = bpfmri_dataset(targnii) nbs = neighbor.volneighbors(mask, 3,26 ) nbs = nbs.compute_offsets() map = GraphMapper(nbs) nds = map(ds) # assert_array_equal(data, map2nifti(nds).get_data()[...,0]) result = map2nifti(nds)
def compute_conn(self): # get neigbors for each voxels targ = np.reshape(self.targ.get_data(), (np.prod(self.dims[0:3]), -1)) if self.mask is not None: mask = self.mask.get_data() else: mask = self.targ.get_data() print np.shape(mask) pdb.set_trace() # tempdata = np.array([[[1,1,1],[2,2,2],[3,3,3]],[[4,4,4],[5,5,5],[6,6,6]],[[7,7,7],[8,8,8],[9,9,9]]]) # tempdata = np.array( # get neigbors for each voxels nbs = neighbor.volneighbors(mask, self.nb[0], self.nb[1]) # nbs = neighbor.volneighbors(tempdata, self.nb[0], self.nb[1]) vnum = nbs.voxnum nbs = nbs.compute_offsets() # compute connectivity matrx I = np.zeros((vnum * 27)) J = np.zeros((vnum * 27)) V = np.zeros((vnum * 27)) count = 0 for v in range(vnum): # print v # print count # pdb.set_trace() vidx = nbs[v][0] # voxel index in image space nbidx = nbs[v][1] # neighbor index in image space # dist = distance.cdist(targ[vidx,:],targ[nbidx,:],self.metric) # dist = np.exp(neurodist) # dist =np.exp(- (nbs[v][2]**2+ nbs[v][3]**2)) dist = np.exp(-nbs[v][2]) # print np.shape(dist) # print dist # I = np.append(I,np.tile(nbs[v][0], nbidx.shape[0])) # in mask index # J = np.append(J,nbs[v][1]) # in mask index # V = np.append(V,dist) nbs_len = len(nbidx) # print nbs_len I[count : count + nbs_len] = np.tile(nbs[v][0], nbidx.shape[0]) # print I[count:count + nbs_len] J[count : count + nbs_len] = nbs[v][1] # print J[count:count + nbs_len] V[count : count + nbs_len] = dist # print V[count:count + nbs_len] # I.append(np.tile(nbs[v][0], nbidx.shape[0])) # J.append(nbs[v][1]) # V.append(dist) count = count + nbs_len pdb.set_trace() print "ok" print np.shape(V) print np.shape(I) print np.shape(J) dims = volgraph.get_dims(self) # total = np.prod(dims) total = np.prod(dims) graph = sparse.csc_matrix((V, (I, J)), shape=(total, total)) return graph
def compute_conn(self): # get neigbors for each voxels targ = np.reshape(self.targ.get_data(), (np.prod(self.dims[0:3]), -1)) if self.mask is not None: mask = self.mask.get_data() else: mask = self.targ.get_data() print np.shape(mask) pdb.set_trace() # tempdata = np.array([[[1,1,1],[2,2,2],[3,3,3]],[[4,4,4],[5,5,5],[6,6,6]],[[7,7,7],[8,8,8],[9,9,9]]]) # tempdata = np.array( # get neigbors for each voxels nbs = neighbor.volneighbors(mask, self.nb[0], self.nb[1]) # nbs = neighbor.volneighbors(tempdata, self.nb[0], self.nb[1]) vnum = nbs.voxnum nbs = nbs.compute_offsets() #compute connectivity matrx I = np.zeros((vnum * 27)) J = np.zeros((vnum * 27)) V = np.zeros((vnum * 27)) count = 0 for v in range(vnum): # print v # print count # pdb.set_trace() vidx = nbs[v][0] # voxel index in image space nbidx = nbs[v][1] # neighbor index in image space # dist = distance.cdist(targ[vidx,:],targ[nbidx,:],self.metric) #dist = np.exp(neurodist) # dist =np.exp(- (nbs[v][2]**2+ nbs[v][3]**2)) dist = np.exp(-nbs[v][2]) # print np.shape(dist) # print dist # I = np.append(I,np.tile(nbs[v][0], nbidx.shape[0])) # in mask index # J = np.append(J,nbs[v][1]) # in mask index # V = np.append(V,dist) nbs_len = len(nbidx) # print nbs_len I[count:count + nbs_len] = np.tile(nbs[v][0], nbidx.shape[0]) # print I[count:count + nbs_len] J[count:count + nbs_len] = nbs[v][1] # print J[count:count + nbs_len] V[count:count + nbs_len] = dist # print V[count:count + nbs_len] # I.append(np.tile(nbs[v][0], nbidx.shape[0])) # J.append(nbs[v][1]) # V.append(dist) count = count + nbs_len pdb.set_trace() print "ok" print np.shape(V) print np.shape(I) print np.shape(J) dims = volgraph.get_dims(self) # total = np.prod(dims) total = np.prod(dims) graph = sparse.csc_matrix((V, (I, J)), shape=(total, total)) return graph