def TPSMatch(self): mx1 = [] my1 = [] mx2 = [] my2 = [] for i in range(len(self.vMatchX)): mx1.append(self.X1[self.vMatchX[i]]) my1.append(self.Y1[self.vMatchX[i]]) mx2.append(self.X2[self.vMatchY[i]]) my2.append(self.Y2[self.vMatchY[i]]) tp = TPS() tp.drawimg = 0 self.vTPS = tp.GetTransform(mx1, my1, mx2, my2) if self.bDraw: self.DrawImg(mx1, my1, mx2, my2) return self.vTPS
def getSectorMap(filename, sector, roi_list, visualize=False, patID=-1, saveToMat=False): """ Get an atlas point cloud registered to a patient with a transformed sector delineation :param filename: the filename of the catlas :param sector: a point cloud representing the sector in atlas coordinate frame :param roi_list: a list of the regions of interest for the patient :param visualize: if True, the method will plot the before and after transformations :param patID: patient ID, if left empty, a random patient will be chosen using the roi_list :param saveToMat: by default, false, but if true, will save to a .mat file called sectors.mat :type filename: str :type sector: numpy.array N x 3 :type roi_list: list[str] :type visualize: bool :type patID: int :type saveToMat: bool :return: A point cloud of the atlas and the sector together and as separate objects :rtype: numpy.array N x 3 """ atlas = get_atlas(filename) atlas = atlas.iterations[-1] print atlas.shape length = sector.shape[0] if patID == -1: patID = query_test_patient(roi_list)[0] fixed_atlas = atlas print('Starting Registration...') transformed, g, wc, errors, patient = register_atlas_to_patient( fixed_atlas, patID, roi_list) print('Registration finished.') wobject = TPS.register(fixed_atlas, transformed, sector) print('TPS finished.') atlas_after = np.append(transformed, wobject, 0) if visualize: print('Visualizing') atlas_before = np.append(atlas, sector, 0) vs.visualizePointCloud(atlas_before, 'Atlas with delineated sector', alpha=0.3, num_points=length, state=1) vs.visualizePointCloud(atlas_after, 'Atlas with sector in patient coordinate frame', alpha=0.3, num_points=length, state=1) if saveToMat: sio.savemat( 'sectors.mat', { 'atlas': atlas, 'transformed': transformed, 'sector': sector, 'ptsector': wobject }) return atlas_after, wobject, transformed
def Chamfer(self): if (len(self.vMatchX) < 10): return [100000, 100000, 100000, 100000] PX1 = [] PY1 = [] PX2 = [] PY2 = [] for i in self.vMatchX: t = i % len(self.X1) PX1.append(self.X1[t]) PY1.append(self.Y1[t]) for i in self.vMatchY: PX2.append(self.X2[i]) PY2.append(self.Y2[i]) #print len(self.X1), len(self.X2) tp = TPS() tp.drawimg = self.bDraw bendingcost = tp.GetTransform(PX1, PY1, PX2, PY2) #DrawMatch(PX1, PY1, PX2, PY2) #print Afft chamfer = 0 resultx = [] resulty = [] for i in range(len(self.X1)): ts = tp.Transform(self.X1[i], self.Y1[i]) resultx.append(ts[0]) resulty.append(ts[1]) mindist = 1e10 for j in range(len(self.X2)): dist = math.sqrt((ts[0] - self.X2[j]) * (ts[0] - self.X2[j]) + (ts[1] - self.Y2[j]) * (ts[1] - self.Y2[j])) if (dist < mindist): mindist = dist chamfer += mindist #DrawMatch(self.X2, self.Y2, resultx, resulty) if (self.DrawImg): DrawIndexMatch(self.X1, self.Y1, self.X2, self.Y2, self.vMatchX, self.vMatchY) return bendingcost + [chamfer]
def Chamfer(self): if (len(self.vMatchX) < 10): return [100000, 100000, 100000, 100000] PX1 =[] PY1 =[] PX2 =[] PY2 =[] for i in self.vMatchX: t = i % len(self.X1) PX1.append(self.X1[t]) PY1.append(self.Y1[t]) for i in self.vMatchY: PX2.append(self.X2[i]) PY2.append(self.Y2[i]) #print len(self.X1), len(self.X2) tp = TPS() tp.drawimg = self.bDraw bendingcost = tp.GetTransform(PX1, PY1, PX2, PY2) #DrawMatch(PX1, PY1, PX2, PY2) #print Afft chamfer = 0 resultx = [] resulty = [] for i in range(len(self.X1)): ts = tp.Transform(self.X1[i], self.Y1[i]) resultx.append(ts[0]) resulty.append(ts[1]) mindist = 1e10 for j in range(len(self.X2)): dist = math.sqrt((ts[0] - self.X2[j]) * (ts[0] - self.X2[j]) + (ts[1] - self.Y2[j]) * ( ts[1] - self.Y2[j])) if (dist < mindist): mindist = dist chamfer += mindist #DrawMatch(self.X2, self.Y2, resultx, resulty) if (self.DrawImg): DrawIndexMatch(self.X1, self.Y1, self.X2, self.Y2, self.vMatchX, self.vMatchY) return bendingcost + [chamfer]