Beispiel #1
0
def test_remove_small_regions():
    data = np.array([[[0., 1., 0.], [0., 1., 1.], [0., 0., 0.]],
                     [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.]],
                     [[0., 0., 1.], [1., 0., 0.], [0., 1., 1.]]])
    # To remove small regions, data should be labelled
    label_map, n_labels = ndimage.label(data)
    sum_label_data = np.sum(label_map)

    affine = np.eye(4)
    min_size = 10
    # data can be act as mask_data to identify regions in label_map because
    # features in label_map are built upon non-zeros in data
    index = np.arange(n_labels + 1)
    removed_data = _remove_small_regions(label_map, index, affine, min_size)
    sum_removed_data = np.sum(removed_data)

    assert sum_removed_data < sum_label_data
def test_remove_small_regions():
    data = np.array([[[0., 1., 0.],
                      [0., 1., 1.],
                      [0., 0., 0.]],
                     [[0., 0., 0.],
                      [1., 0., 0.],
                      [0., 1., 0.]],
                     [[0., 0., 1.],
                      [1., 0., 0.],
                      [0., 1., 1.]]])
    # To remove small regions, data should be labelled
    label_map, n_labels = ndimage.label(data)
    sum_label_data = np.sum(label_map)

    affine = np.eye(4)
    min_size = 10
    # data can be act as mask_data to identify regions in label_map because
    # features in label_map are built upon non-zeros in data
    index = np.arange(n_labels + 1)
    removed_data = _remove_small_regions(label_map, index, affine, min_size)
    sum_removed_data = np.sum(removed_data)

    assert_true(sum_removed_data < sum_label_data)