def ncut(self): # dims = (3,3,3) dims = (91, 109, 91) graphconn = self.graph.compute_conn() total = np.shape(graphconn)[0] print "1" print np.shape(graphconn) print np.max(self.ncluster) pdb.set_trace() eigenval, eigenvec = pyncut.ncut(graphconn, np.max(self.ncluster)) # Discretize to label # self.labelcut = np.array(eigenvec.shape[0], len(self.ncluster)) # for c in range(self.ncluster): # eigk = eigenvec[:,:c] # print eigk eigenvec_discrete = pyncut.discretisation(eigenvec) img_outfile_1d = eigenvec_discrete[:, 0] for i in range(self.ncluster): img_outfile_1d = img_outfile_1d + (i + 1) * eigenvec_discrete[:, i] img_outfile_1d = list(img_outfile_1d.todense()) img_outfile_3d = np.reshape(img_outfile_1d, dims) print "ok" # name = "mytest.nii.gz" # nib.save(img_outfile_3d,name) return img_outfile_3d
def _ncut(self,graph,ncluster,dims): total = np.prod(dims) eigenval, eigenvec = pyncut.ncut(graph,ncluster) eigenvec_discrete= pyncut.descretisation(eigenvec) markers = eigenvec_discrete[:,0] for i in range(total): markers = markers + (i + 1) * eigenvec_discrete[:,i] markers = markers.todense() return markers