def test_get_directions_list(): # test if the border point after is rotated to the expected direction test_array = np.array([[[0, 1, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]], dtype=np.uint8) directions_list = rotational_operators.get_directions_list(test_array) # expected index where 1 occurs after one of the rotation in 12 directions expected_results = [1, 23, 15, 5, 9, 25, 3, 19, 17, 21, 11, 7] for expected_result, direction in zip(expected_results, directions_list): nose.tools.assert_true(direction.reshape(27).tolist()[expected_result]) nose.tools.assert_true(direction.sum())
def test_rotations_are_unique(): test_array = np.array( [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 1, 0]]], dtype=np.uint8) directions_list = ops.get_directions_list(test_array) for n, dir1 in enumerate(directions_list): for m, dir2 in enumerate(directions_list): if n == m: continue with nose.tools.assert_raises(AssertionError): np.testing.assert_array_equal(dir1, dir2) nose.tools.assert_equal(dir1.sum(), 1)
def _get_voxel_deletion_flag(neighbor_values, direction): """ Returns self.a flag saying self.voxel should be deleted or not Parameters ---------- neighbor_values : list list of first order neighborhood (26 voxels) of a nonzero value at origin direction : array transformation array describing rotation of cube to remove boundary voxels in a different direction Returns ------- should_voxel_be_deleted : boolean 0 => should not be deleted 1 => should be deleted """ assert len(neighbor_values) == 27 # reshape neighbor_values to a 3 x 3 x 3 cube neighbor_matrix = np.reshape(neighbor_values, (3, 3, 3)) # transform neighbor_values to direction neighbor_values = get_directions_list(neighbor_matrix)[direction] neighbor_values = list(np.reshape(neighbor_values, 27)) del (neighbor_values[13]) # assign 26 voxels in a 2nd ordered neighborhood of a 3D voxels as 26 alphabet variables neighbor_values = tuple(neighbor_values) # insert aplhabetical variables into equations of templates for deleting the boundary voxel template = Templates(*neighbor_values) should_voxel_be_deleted = functools.reduce(lambda x, y: x | y, [ template.first_template(), template.second_template(), template.third_template(), template.fourth_template(), template.fifth_template(), template.sixth_template(), template.seventh_template(), template.eighth_template(), template.ninth_template(), template.tenth_template(), template.eleventh_template(), template.twelveth_template(), template.thirteenth_template(), template.fourteenth_template() ]) return should_voxel_be_deleted
def test_get_directions_list(): # test if the border point after is rotated to the expected direction test_array = np.array( [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 1, 0]]], dtype=np.uint8) directions_list = ops.get_directions_list(test_array) # expected index where 1 occurs after one of the rotation in 12 directions expected_results = [1, 23, 15, 5, 9, 25, 3, 19, 17, 21, 11, 7] for index, (expected_result, direction) in enumerate(zip(expected_results, directions_list)): nose.tools.assert_true(direction.reshape(27).tolist()[expected_result], msg="fails at %i th direction" % index) nose.tools.assert_true(direction.sum(), msg="fails at %i th direction" % index)
def _get_voxel_deletion_flag(neighbor_values, direction): """ Returns self.a flag saying self.voxel should be deleted or not Parameters ---------- neighbor_values : list list of first order neighborhood (26 voxels) of a nonzero value at origin direction : array transformation array describing rotation of cube to remove boundary voxels in a different direction Returns ------- should_voxel_be_deleted : boolean 0 => should not be deleted 1 => should be deleted """ assert len(neighbor_values) == 27 # reshape neighbor_values to a 3 x 3 x 3 cube neighbor_matrix = np.reshape(neighbor_values, (3, 3, 3)) # transform neighbor_values to direction neighbor_values = get_directions_list(neighbor_matrix)[direction] neighbor_values = list(np.reshape(neighbor_values, 27)) del(neighbor_values[13]) # assign 26 voxels in a 2nd ordered neighborhood of a 3D voxels as 26 alphabet variables neighbor_values = tuple(neighbor_values) # insert aplhabetical variables into equations of templates for deleting the boundary voxel template = Templates(*neighbor_values) should_voxel_be_deleted = functools.reduce(lambda x, y: x | y, [template.first_template(), template.second_template(), template.third_template(), template.fourth_template(), template.fifth_template(), template.sixth_template(), template.seventh_template(), template.eighth_template(), template.ninth_template(), template.tenth_template(), template.eleventh_template(), template.twelveth_template(), template.thirteenth_template(), template.fourteenth_template()]) return should_voxel_be_deleted