def test_symmetrise_data_y_axis(): cube_id = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]]]) cube_sym_y2_be_T = np.array([[[0, 1, 1, 0], [4, 5, 5, 4], [8, 9, 9, 8], [12, 13, 13, 12]], [[16, 17, 17, 16], [20, 21, 21, 20], [24, 25, 25, 24], [28, 29, 29, 28]]]) cube_sym_y2_ab_T = np.array([[[3, 2, 2, 3], [7, 6, 6, 7], [11, 10, 10, 11], [15, 14, 14, 15]], [[19, 18, 18, 19], [23, 22, 22, 23], [27, 26, 26, 27], [31, 30, 30, 31]]]) cube_sym_y3_be_F = np.array([[[0, 1, 2, 2, 1, 0], [4, 5, 6, 6, 5, 4], [8, 9, 10, 10, 9, 8], [12, 13, 14, 14, 13, 12]], [[16, 17, 18, 18, 17, 16], [20, 21, 22, 22, 21, 20], [24, 25, 26, 26, 25, 24], [28, 29, 30, 30, 29, 28]]]) cube_sym_y3_be_T = np.array([[[0, 1, 2, 2], [4, 5, 6, 6], [8, 9, 10, 10], [12, 13, 14, 14]], [[16, 17, 18, 18], [20, 21, 22, 22], [24, 25, 26, 26], [28, 29, 30, 30]]]) assert_array_equal( symmetrise_data(cube_id, axis_direction='y', plane_intercept=2, side_to_copy='below', keep_in_data_dimensions_boundaries=True), cube_sym_y2_be_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='y', plane_intercept=2, side_to_copy='above', keep_in_data_dimensions_boundaries=True), cube_sym_y2_ab_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='y', plane_intercept=3, side_to_copy='below', keep_in_data_dimensions_boundaries=False), cube_sym_y3_be_F) assert_array_equal( symmetrise_data(cube_id, axis_direction='y', plane_intercept=3, side_to_copy='below', keep_in_data_dimensions_boundaries=True), cube_sym_y3_be_T)
def test_symmetrise_data_x_axis(): cube_id = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]]]) cube_sym_x2_be_T = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [4, 5, 6, 7], [0, 1, 2, 3]], [[16, 17, 18, 19], [20, 21, 22, 23], [20, 21, 22, 23], [16, 17, 18, 19]]]) cube_sym_x2_ab_T = np.array([[[12, 13, 14, 15], [8, 9, 10, 11], [8, 9, 10, 11], [12, 13, 14, 15]], [[28, 29, 30, 31], [24, 25, 26, 27], [24, 25, 26, 27], [28, 29, 30, 31]]]) cube_sym_x3_be_F = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [8, 9, 10, 11], [4, 5, 6, 7], [0, 1, 2, 3]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [24, 25, 26, 27], [20, 21, 22, 23], [16, 17, 18, 19]]]) cube_sym_x3_be_T = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [8, 9, 10, 11]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [24, 25, 26, 27]]]) assert_array_equal( symmetrise_data(cube_id, axis_direction='x', plane_intercept=2, side_to_copy='below', keep_in_data_dimensions_boundaries=True), cube_sym_x2_be_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='x', plane_intercept=2, side_to_copy='above', keep_in_data_dimensions_boundaries=True), cube_sym_x2_ab_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='x', plane_intercept=3, side_to_copy='below', keep_in_data_dimensions_boundaries=False), cube_sym_x3_be_F) assert_array_equal( symmetrise_data(cube_id, axis_direction='x', plane_intercept=3, side_to_copy='below', keep_in_data_dimensions_boundaries=True), cube_sym_x3_be_T)
def test_symmetrise_data_z_axis(): cube_id = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47]]]) cube_sym_z2_be_T = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]]]) cube_sym_z1_ab_T = np.array([[[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47]]]) cube_sym_z1_ab_F = np.array([[[32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], [[32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47]]]) assert_array_equal( symmetrise_data(cube_id, axis_direction='z', plane_intercept=2, side_to_copy='below', keep_in_data_dimensions_boundaries=True), cube_sym_z2_be_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='z', plane_intercept=1, side_to_copy='above', keep_in_data_dimensions_boundaries=True), cube_sym_z1_ab_T) assert_array_equal( symmetrise_data(cube_id, axis_direction='z', plane_intercept=1, side_to_copy='above', keep_in_data_dimensions_boundaries=False), cube_sym_z1_ab_F)
def symmetrise_axial(self, filename_in, filename_out=None, axis='x', plane_intercept=10, side_to_copy='below', keep_in_data_dimensions=True): pfi_in, pfi_out = get_pfi_in_pfi_out(filename_in, filename_out, self.pfo_in, self.pfo_out) im_segm = nib.load(pfi_in) data_labels = im_segm.get_data() data_symmetrised = symmetrise_data(data_labels, axis_direction=axis, plane_intercept=plane_intercept, side_to_copy=side_to_copy, keep_in_data_dimensions_boundaries=keep_in_data_dimensions) im_symmetrised = set_new_data(im_segm, data_symmetrised) nib.save(im_symmetrised, pfi_out) print('Symmetrised axis {0}, plane_intercept {1}, image of {2} saved in {3}.'.format(axis, plane_intercept, pfi_in, pfi_out)) return pfi_out
def test_symmetrise_data_error_input_axis_direction(): with assert_raises(IOError): symmetrise_data(np.ones([5, 5, 5]), axis_direction='s')
def test_symmetrise_data_error_input_side_to_copy(): with assert_raises(IOError): symmetrise_data(np.ones([5, 5, 5]), side_to_copy='spam')
def test_symmetrise_data_error_input_ndim(): with assert_raises(IOError): symmetrise_data(np.ones([5, 5, 5, 5]))