Beispiel #1
0
def test_build_gaussian_pyramid_rgb():
    rows, cols, dim = image.shape
    pyramid = pyramids.pyramid_gaussian(image, downscale=2,
                                        multichannel=True)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim)
        assert_array_equal(out.shape, layer_shape)
Beispiel #2
0
def test_build_gaussian_pyramid_gray():
    rows, cols = image_gray.shape
    pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2,
                                        multichannel=False)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2 ** layer, cols / 2 ** layer)
        assert_array_equal(out.shape, layer_shape)
Beispiel #3
0
def test_build_gaussian_pyramid_gray():
    rows, cols = image_gray.shape
    with expected_warnings(['The default multichannel']):
        pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2)
        for layer, out in enumerate(pyramid):
            layer_shape = (rows / 2**layer, cols / 2**layer)
            assert_array_equal(out.shape, layer_shape)
Beispiel #4
0
def test_build_gaussian_pyramid_rgb_deprecated_multichannel():
    rows, cols, dim = image.shape
    with expected_warnings(["`multichannel` is a deprecated argument"]):
        pyramid = pyramids.pyramid_gaussian(image, downscale=2,
                                            multichannel=True)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim)
        assert_array_equal(out.shape, layer_shape)

    # repeat prior test, but check for positional multichannel warning
    with expected_warnings(["Providing the `multichannel` argument"]):
        pyramid = pyramids.pyramid_gaussian(image, -1, 2, None, 1, 'reflect',
                                            0, True)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim)
        assert_array_equal(out.shape, layer_shape)
def test_build_gaussian_pyramid_gray():
    rows, cols = image_gray.shape
    with expected_warnings(['The default multichannel']):
        pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2)
        for layer, out in enumerate(pyramid):
            layer_shape = (rows / 2 ** layer, cols / 2 ** layer)
            assert_array_equal(out.shape, layer_shape)
Beispiel #6
0
def test_build_gaussian_pyramid_nd():
    for ndim in [1, 2, 3, 4]:
        img = np.random.randn(*((8, ) * ndim))
        original_shape = np.asarray(img.shape)
        pyramid = pyramids.pyramid_gaussian(img, downscale=2,
                                            multichannel=False)
        for layer, out in enumerate(pyramid):
            layer_shape = original_shape / 2 ** layer
            assert_array_equal(out.shape, layer_shape)
def test_build_gaussian_pyramid_nd():
    for ndim in [1, 2, 3, 4]:
        img = np.random.randn(*((8, ) * ndim))
        original_shape = np.asarray(img.shape)
        pyramid = pyramids.pyramid_gaussian(img, downscale=2,
                                            multichannel=False)
        for layer, out in enumerate(pyramid):
            layer_shape = original_shape / 2 ** layer
            assert_array_equal(out.shape, layer_shape)
Beispiel #8
0
def test_build_gaussian_pyramid_rgb(channel_axis):
    image = data.astronaut()
    rows, cols, dim = image.shape
    image = np.moveaxis(image, source=-1, destination=channel_axis)
    pyramid = pyramids.pyramid_gaussian(image,
                                        downscale=2,
                                        channel_axis=channel_axis)
    for layer, out in enumerate(pyramid):
        layer_shape = [rows / 2**layer, cols / 2**layer]
        layer_shape.insert(channel_axis % image.ndim, dim)
        assert out.shape == tuple(layer_shape)
def test_build_gaussian_pyramid_gray():
    rows, cols = image_gray.shape
    pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2 ** layer, cols / 2 ** layer)
        assert_array_equal(out.shape, layer_shape)
Beispiel #10
0
def test_build_gaussian_pyramid_gray_defaults():
    rows, cols = image_gray.shape
    pyramid = pyramids.pyramid_gaussian(image_gray)
    for layer, out in enumerate(pyramid):
        layer_shape = (rows / 2**layer, cols / 2**layer)
        assert_array_equal(out.shape, layer_shape)
Beispiel #11
0
def test_pyramid_gaussian_dtype_support(dtype, expected):
    img = np.random.randn(32, 8).astype(dtype)
    pyramid = pyramids.pyramid_gaussian(img)

    assert np.all([im.dtype == expected for im in pyramid])
Beispiel #12
0
# Main function
if __name__ == "__main__":

    # Load image and convert to grayscale
    visual_attention = imread(
        "C:/Users/Moritz Lahann/Desktop/STUDIUM/Module IAS/Computer Vision/cv_exercises/cv_ex02_03/visual_attention.png",
        as_gray=True,
    )
    fig, ax = plt.subplots()
    ax.imshow(visual_attention)
    plt.title("Input image")
    plt.show()

    # Calculate center pyramid
    center_pyramid = tuple(pyramid_gaussian(visual_attention, max_layer=4, sigma=9))

    # Visualize center pyramid
    fig = show_pyramid(center_pyramid)
    fig.suptitle("Center Pyramid")
    plt.show()

    # Calculate surround pyramid
    surround_pyramid = tuple(pyramid_gaussian(visual_attention, max_layer=4, sigma=16))

    # Visualize surround pyramid
    fig = show_pyramid(surround_pyramid)
    fig.suptitle("Surround Pyramid")
    plt.show()

    # Calculate on-off contrast pyramid