示例#1
0
def test_denoise_wavelet_biorthogonal():
    """Biorthogonal wavelets should raise a warning during thresholding."""
    img = astro_gray
    assert_warns(UserWarning,
                 restoration.denoise_wavelet,
                 img,
                 wavelet='bior2.2',
                 multichannel=False)
def test_denoise_wavelet_biorthogonal(rescale_sigma):
    """Biorthogonal wavelets should raise a warning during thresholding."""
    img = astro_gray
    assert_warns(UserWarning,
                 restoration.denoise_wavelet,
                 img,
                 wavelet='bior2.2',
                 channel_axis=None,
                 rescale_sigma=rescale_sigma)
示例#3
0
def test_denoise_bilateral_nan():
    img = np.full((50, 50), np.NaN)
    out = assert_warns(RuntimeWarning,
                       restoration.denoise_bilateral,
                       img,
                       multichannel=False)
    assert_equal(img, out)
示例#4
0
def test_few_points():
    image = np.array(
        [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]],
        dtype=np.uint8)
    image3d = np.stack([image, image, image])
    with testing.assert_warns(UserWarning):
        chimage3d = convex_hull_image(image3d)
        assert_array_equal(chimage3d, np.zeros(image3d.shape, dtype=bool))
示例#5
0
def test_estimate_sigma_color():
    rstate = np.random.RandomState(1234)
    # astronaut image
    img = astro.copy()
    sigma = 0.1
    # add noise to astronaut
    img += sigma * rstate.standard_normal(img.shape)

    sigma_est = restoration.estimate_sigma(img, multichannel=True,
                                           average_sigmas=True)
    assert_almost_equal(sigma, sigma_est, decimal=2)

    sigma_list = restoration.estimate_sigma(img, multichannel=True,
                                            average_sigmas=False)
    assert_equal(len(sigma_list), img.shape[-1])
    assert_almost_equal(sigma_list[0], sigma_est, decimal=2)

    # default multichannel=False should raise a warning about last axis size
    assert_warns(UserWarning, restoration.estimate_sigma, img)
示例#6
0
def test_estimate_sigma_color():
    rstate = np.random.RandomState(1234)
    # astronaut image
    img = astro.copy()
    sigma = 0.1
    # add noise to astronaut
    img += sigma * rstate.standard_normal(img.shape)

    sigma_est = restoration.estimate_sigma(img, multichannel=True,
                                           average_sigmas=True)
    assert_almost_equal(sigma, sigma_est, decimal=2)

    sigma_list = restoration.estimate_sigma(img, multichannel=True,
                                            average_sigmas=False)
    assert_equal(len(sigma_list), img.shape[-1])
    assert_almost_equal(sigma_list[0], sigma_est, decimal=2)

    # default multichannel=False should raise a warning about last axis size
    assert_warns(UserWarning, restoration.estimate_sigma, img)
示例#7
0
def test_hessian_matrix():
    square = np.zeros((5, 5))
    square[2, 2] = 4
    Hrr, Hrc, Hcc = hessian_matrix(square, sigma=0.1, order='rc')
    assert_almost_equal(
        Hrr,
        np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [2, 0, -2, 0, 2],
                  [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    assert_almost_equal(
        Hrc,
        np.array([[0, 0, 0, 0, 0], [0, 1, 0, -1, 0], [0, 0, 0, 0, 0],
                  [0, -1, 0, 1, 0], [0, 0, 0, 0, 0]]))

    assert_almost_equal(
        Hcc,
        np.array([[0, 0, 2, 0, 0], [0, 0, 0, 0, 0], [0, 0, -2, 0, 0],
                  [0, 0, 0, 0, 0], [0, 0, 2, 0, 0]]))

    matrix2d = np.random.rand(3, 3)
    assert_warns(UserWarning, hessian_matrix, matrix2d, sigma=0.1)
示例#8
0
def test_3D():
    grey_img = np.zeros((10, 10))
    rgb_img = np.zeros((10, 10, 3))
    three_d_img = np.zeros((10, 10, 10))
    with assert_no_warnings():
        felzenszwalb(grey_img, multichannel=True)
        felzenszwalb(grey_img, multichannel=False)
        felzenszwalb(rgb_img, multichannel=True)
    with assert_warns(RuntimeWarning):
        felzenszwalb(three_d_img, multichannel=True)
    with testing.raises(ValueError):
        felzenszwalb(rgb_img, multichannel=False)
        felzenszwalb(three_d_img, multichannel=False)
def test_estimate_sigma_color(channel_axis):
    rstate = np.random.RandomState(1234)
    # astronaut image
    img = astro.copy()
    sigma = 0.1
    # add noise to astronaut
    img += sigma * rstate.standard_normal(img.shape)
    img = np.moveaxis(img, -1, channel_axis)

    sigma_est = restoration.estimate_sigma(img,
                                           channel_axis=channel_axis,
                                           average_sigmas=True)
    assert_almost_equal(sigma, sigma_est, decimal=2)

    sigma_list = restoration.estimate_sigma(img,
                                            channel_axis=channel_axis,
                                            average_sigmas=False)
    assert_equal(len(sigma_list), img.shape[channel_axis])
    assert_almost_equal(sigma_list[0], sigma_est, decimal=2)

    if channel_axis % img.ndim == 2:
        # default channel_axis=None should raise a warning about last axis size
        assert_warns(UserWarning, restoration.estimate_sigma, img)
示例#10
0
def test_hessian_matrix():
    square = np.zeros((5, 5))
    square[2, 2] = 4
    Hrr, Hrc, Hcc = hessian_matrix(square, sigma=0.1, order='rc')
    assert_almost_equal(Hrr, np.array([[0, 0,  0, 0, 0],
                                       [0, 0,  0, 0, 0],
                                       [2, 0, -2, 0, 2],
                                       [0, 0,  0, 0, 0],
                                       [0, 0,  0, 0, 0]]))

    assert_almost_equal(Hrc, np.array([[0,  0, 0,  0, 0],
                                       [0,  1, 0, -1, 0],
                                       [0,  0, 0,  0, 0],
                                       [0, -1, 0,  1, 0],
                                       [0,  0, 0,  0, 0]]))

    assert_almost_equal(Hcc, np.array([[0, 0,  2, 0, 0],
                                       [0, 0,  0, 0, 0],
                                       [0, 0, -2, 0, 0],
                                       [0, 0,  0, 0, 0],
                                       [0, 0,  2, 0, 0]]))

    matrix2d = np.random.rand(3, 3)
    assert_warns(UserWarning, hessian_matrix, matrix2d, sigma=0.1)
示例#11
0
def test_3D(channel_axis):
    grey_img = np.zeros((10, 10))
    rgb_img = np.zeros((10, 10, 3))
    three_d_img = np.zeros((10, 10, 10))

    rgb_img = np.moveaxis(rgb_img, -1, channel_axis)
    with assert_no_warnings():
        felzenszwalb(grey_img, channel_axis=-1)
        felzenszwalb(grey_img, channel_axis=None)
        felzenszwalb(rgb_img, channel_axis=channel_axis)
    with assert_warns(RuntimeWarning):
        felzenszwalb(three_d_img, channel_axis=channel_axis)
    with testing.raises(ValueError):
        felzenszwalb(rgb_img, channel_axis=None)
        felzenszwalb(three_d_img, channel_axis=None)
示例#12
0
def test_wavelet_rescale_sigma_deprecation():
    # No specifying rescale_sigma results in a DeprecationWarning
    assert_warns(FutureWarning, restoration.denoise_wavelet, np.ones(16))
示例#13
0
def test_negative_intensity():
    labels = np.arange(100).reshape(10, 10)
    image = np.full((10, 10), -1, dtype='float64')
    assert_warns(UserWarning, label2rgb, labels, image, bg_label=-1)
示例#14
0
def test_denoise_wavelet_biorthogonal():
    """Biorthogonal wavelets should raise a warning during thresholding."""
    img = astro_gray
    assert_warns(UserWarning, restoration.denoise_wavelet, img,
                 wavelet='bior2.2', multichannel=False)
示例#15
0
def test_views_non_contiguous():
    A = np.arange(16).reshape((4, 4))
    A = A[::2, :]

    assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2))
    assert_warns(RuntimeWarning, view_as_windows, A, (2, 2))
示例#16
0
def test_views_non_contiguous():
    A = np.arange(16).reshape((4, 4))
    A = A[::2, :]

    assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2))
    assert_warns(RuntimeWarning, view_as_windows, A, (2, 2))
示例#17
0
def test_multichannel_warnings():
    img = data.astronaut()
    assert_warns(UserWarning, restoration.denoise_bilateral, img)
    assert_warns(UserWarning, restoration.denoise_nl_means, img)
示例#18
0
def test_negative_intensity():
    labels = np.arange(100).reshape(10, 10)
    image = -1 * np.ones((10, 10))
    assert_warns(UserWarning, label2rgb, labels, image)