def main(): """ Main function """ # make marker coordinates dictionary markers = { 'markers_1' : (coordinates_file, marker_initial_rows), 'markers_2' : (coordinates_file, marker_final_rows) } # establish correlation corr = Basic() corr.readPositions( points=markers, format_=file_format, comments=comments, skiprows=skiprows, delimiter=delimiter, columns=columns, indexing=indexing) corr.establish(type_=transform_type) # corrtale target coordinates targets = { 'targets_1' : (coordinates_file, target_initial_rows), 'targets_2' : (coordinates_file, target_final_rows) } corr.readPositions( points=targets, format_=file_format, comments=comments, skiprows=skiprows, delimiter=delimiter, columns=columns, indexing=indexing) corr.correlate() # write results write_results(corr=corr, res_file_name=results_file)
def main(): """ Main function """ # establish correlation corr = Basic() corr.establish( markers_1=markers_initial, markers_2=markers_final, type_=transform_type) # print transformation parameters print "Transformation parameters: " print "Rotation angle: ", corr.transf_1_to_2.phiDeg print "Scales: ", corr.transf_1_to_2.scale print "Parity: ", corr.transf_1_to_2.parity print "Shear: ", corr.transf_1_to_2.shear print "Translation: ", corr.transf_1_to_2.d print "RME error: ", corr.transf_1_to_2.rmsError print "Individual marker errors: " print corr.transf_1_to_2.error corr.correlate(targets_1=target_initial) print " " print "System 1 targets correlated to system 2: " print corr.correlated_1_to_2 corr.correlate(targets_2=target_final) print " " print "System 2 targets correlated to system 1: " print corr.correlated_2_to_1
def testReadPositions(self): """ Tests readPositions() """ corr = Basic() # indexing 1 (default) points = {'markers': (self.imagej_file, [3, 4, 5]), 'targets': (self.imagej_file, [6, 7, 8])} corr.readPositions(points=points, format_='imagej', columns=[8,9]) desired_markers = numpy.array([[120, 114.667], [103.333, 108], [126, 130.667]]) np_test.assert_almost_equal(corr.markers, desired_markers) desired_targets = numpy.array([[221.333, 72.667], [121.333, 172.667], [106.667, 278.667]]) np_test.assert_almost_equal(corr.targets, desired_targets) # indexing 0 (old way) points = {'markers': (self.imagej_file, [2, 3, 4]), 'targets': (self.imagej_file, [5, 6, 7])} corr.readPositions(points=points, format_='imagej', columns=[7, 8], indexing=0) np_test.assert_almost_equal(corr.markers, desired_markers) np_test.assert_almost_equal(corr.targets, desired_targets)
def testGetTransformation(self): """ Tasts getTransformation() """ corr = Basic() corr.markers_1 = self.x1 corr.markers_2 = self.y1 corr.establish() np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).gl, corr.transf_1_to_2.gl) np_test.assert_almost_equal(corr.getTransformation(from_=2, to=1).gl, corr.transf_2_to_1.gl)
def testDecompose(self): """ Tests decompose() """ corr = Basic() corr.establish(markers_1=self.x1, markers_2=self.y1) corr.decompose(order='qpsm') np_test.assert_almost_equal(corr.transf_1_to_2.phi, numpy.arctan(0.5)) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).scale, [numpy.sqrt(5)] * 2) np_test.assert_almost_equal(corr.getTransformation(from_=2, to=1).phi, -numpy.arctan(0.5)) np_test.assert_almost_equal(corr.transf_2_to_1.scale, [1/numpy.sqrt(5)] * 2)
def testCorrelate(self): """ Tests correlate """ # establish correlation corr = Basic() corr.establish(markers_1=self.x1, markers_2=self.y1) # test mixed set and passed targets corr.targets_2 = self.y1[0:2] corr.correlate(targets_1=self.x1[2:4]) np_test.assert_almost_equal(corr.correlated_1_to_2, self.y1[2:4]) np_test.assert_almost_equal(corr.getTargets(from_=2, to=1), self.x1[0:2]) # test mixed set and passed targets, set need to be overwritten corr.targets_1 = self.x1[2:4] * 3.1 # bad corr.targets_2 = self.y1[0:2] corr.correlate(targets_1=self.x1[2:4]) np_test.assert_almost_equal(corr.correlated_1_to_2, self.y1[2:4]) np_test.assert_almost_equal(corr.getTargets(from_=2, to=1), self.x1[0:2])
def testEstablish(self): """ Tests establish() """ # markers read from a file corr = Basic() points = {'markers_1': (self.imagej_file, [3, 4, 5]), 'markers_2': (self.imagej_file, [6, 7, 8])} corr.establish(points=points, format_='imagej', columns=[8,9]) desired_markers = numpy.array([[120, 114.667], [103.333, 108], [126, 130.667]]) np_test.assert_almost_equal(corr.markers_1, desired_markers) desired_markers = numpy.array([[221.333, 72.667], [121.333, 172.667], [106.667, 278.667]]) np_test.assert_almost_equal(corr.markers_2, desired_markers) # markers given in arguments corr = Basic() corr.establish(markers_1=self.x1, markers_2=self.y1) np_test.assert_equal(isinstance(corr.getTransformation(from_=1, to=2), Affine2D), True) np_test.assert_almost_equal(corr.markers_1, self.x1) np_test.assert_almost_equal(corr.markers_2, self.y1) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).gl, self.af1_gl) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).d, self.af1_d) # markers set corr = Basic() corr.markers_1 = self.x1 corr.markers_2 = self.y1 corr.establish() np_test.assert_almost_equal(corr.markers_1, self.x1) np_test.assert_almost_equal(corr.markers_2, self.y1) transf_1_to_2 = corr.getTransformation(from_=1, to=2) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).gl, self.af1_gl) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).d, self.af1_d) transf_2_to_1 = corr.getTransformation(from_=2, to=1) np_test.assert_almost_equal(transf_2_to_1.gl, transf_1_to_2.inverse().gl) np_test.assert_almost_equal(transf_2_to_1.d, transf_1_to_2.inverse().d) # markers mixed corr = Basic() corr.markers_1 = self.x1 *2.1 # set wrong to check if overwritten corr.markers_2 = self.y1 corr.establish(markers_1=self.x1) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).gl, self.af1_gl) np_test.assert_almost_equal(corr.getTransformation(from_=1, to=2).d, self.af1_d)