mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-19 11:27:45 +08:00
Full test coverage for image pyramids
This commit is contained in:
committed by
Stefan van der Walt
parent
e2dec8339c
commit
7f100ac1b4
@@ -1,41 +1,72 @@
|
||||
from numpy.testing import assert_array_equal, run_module_suite
|
||||
from numpy.testing import assert_array_equal, assert_raises, run_module_suite
|
||||
from skimage import data
|
||||
from skimage.transform import (pyramid_reduce, pyramid_expand,
|
||||
pyramid_gaussian, pyramid_laplacian)
|
||||
from skimage.transform import pyramids
|
||||
|
||||
|
||||
image = data.lena()
|
||||
image_gray = image[..., 0]
|
||||
|
||||
|
||||
def test_pyramid_reduce():
|
||||
# RGB image
|
||||
rows, cols, dim = image.shape
|
||||
out = pyramid_reduce(image, downscale=2)
|
||||
out = pyramids.pyramid_reduce(image, downscale=2)
|
||||
assert_array_equal(out.shape, (rows / 2, cols / 2, dim))
|
||||
|
||||
# grayscale image
|
||||
rows, cols = image_gray.shape
|
||||
out = pyramids.pyramid_reduce(image_gray, downscale=2)
|
||||
assert_array_equal(out.shape, (rows / 2, cols / 2))
|
||||
|
||||
|
||||
def test_pyramid_expand():
|
||||
# RGB image
|
||||
rows, cols, dim = image.shape
|
||||
out = pyramid_expand(image, upscale=2)
|
||||
out = pyramids.pyramid_expand(image, upscale=2)
|
||||
assert_array_equal(out.shape, (rows * 2, cols * 2, dim))
|
||||
|
||||
# grayscale image
|
||||
rows, cols = image_gray.shape
|
||||
out = pyramids.pyramid_expand(image_gray, upscale=2)
|
||||
assert_array_equal(out.shape, (rows * 2, cols * 2))
|
||||
|
||||
|
||||
def test_build_gaussian_pyramid():
|
||||
# RGB image
|
||||
rows, cols, dim = image.shape
|
||||
pyramid = pyramid_gaussian(image, downscale=2)
|
||||
|
||||
pyramid = pyramids.pyramid_gaussian(image, downscale=2)
|
||||
for layer, out in enumerate(pyramid):
|
||||
layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim)
|
||||
assert_array_equal(out.shape, layer_shape)
|
||||
|
||||
# grayscale image
|
||||
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)
|
||||
|
||||
|
||||
def test_build_laplacian_pyramid():
|
||||
# RGB image
|
||||
rows, cols, dim = image.shape
|
||||
pyramid = pyramid_laplacian(image, downscale=2)
|
||||
|
||||
pyramid = pyramids.pyramid_laplacian(image, downscale=2)
|
||||
for layer, out in enumerate(pyramid):
|
||||
layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim)
|
||||
assert_array_equal(out.shape, layer_shape)
|
||||
|
||||
# grayscale image
|
||||
rows, cols = image_gray.shape
|
||||
pyramid = pyramids.pyramid_laplacian(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)
|
||||
|
||||
|
||||
def test_check_factor():
|
||||
assert_raises(ValueError, pyramids._check_factor, 0.99)
|
||||
assert_raises(ValueError, pyramids._check_factor, - 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user