Exemplo n.º 1
0
def test_rotate_resize():
    x = np.zeros((10, 10), dtype=np.double)

    x45 = rotate(x, 45, resize=False)
    assert x45.shape == (10, 10)

    x45 = rotate(x, 45, resize=True)
    # new dimension should be d = sqrt(2 * (10/2)^2)
    assert x45.shape == (14, 14)
Exemplo n.º 2
0
def test_rotate_center():
    x = np.zeros((10, 10), dtype=np.double)
    x[4, 4] = 1
    refx = np.zeros((10, 10), dtype=np.double)
    refx[2, 5] = 1
    x20 = rotate(x, 20, order=0, center=(0, 0))
    assert_array_almost_equal(x20, refx)
    x0 = rotate(x20, -20, order=0, center=(0, 0))
    assert_array_almost_equal(x0, x)
Exemplo n.º 3
0
def test_order_0_warp_dtype(dtype):

    img = _convert(astronaut()[:10, :10, 0], dtype)

    assert resize(img, (12, 12), order=0).dtype == dtype
    assert rescale(img, 0.5, order=0).dtype == dtype
    assert rotate(img, 45, order=0).dtype == dtype
    assert warp_polar(img, order=0).dtype == dtype
    assert swirl(img, order=0).dtype == dtype
Exemplo n.º 4
0
def test_nonzero_order_warp_dtype(dtype, order):

    img = _convert(astronaut()[:10, :10, 0], dtype)

    float_dtype = _supported_float_type(dtype)

    assert resize(img, (12, 12), order=order).dtype == float_dtype
    assert rescale(img, 0.5, order=order).dtype == float_dtype
    assert rotate(img, 45, order=order).dtype == float_dtype
    assert warp_polar(img, order=order).dtype == float_dtype
    assert swirl(img, order=order).dtype == float_dtype
Exemplo n.º 5
0
def test_rotate_resize_center():
    x = np.zeros((10, 10), dtype=np.double)
    x[0, 0] = 1

    ref_x45 = np.zeros((14, 14), dtype=np.double)
    ref_x45[6, 0] = 1
    ref_x45[7, 0] = 1

    x45 = rotate(x, 45, resize=True, center=(3, 3), order=0, mode='reflect')
    # new dimension should be d = sqrt(2 * (10/2)^2)
    assert x45.shape == (14, 14)
    assert_array_equal(x45, ref_x45)
Exemplo n.º 6
0
def test_warp_clip_cval_is_nan(order):
    # Test that clipping works as intended when cval is NaN
    # Orders 2, 4, and 5 do not produce good output when cval is NaN, so those
    # orders are not tested

    x = np.ones((15, 15), dtype=np.float64)
    x[5:-5, 5:-5] = 2

    outx = rotate(x, 45, order=order, cval=np.nan, resize=True, clip=True)

    assert_array_almost_equal(np.nanmin(outx), 1)
    assert_array_almost_equal(np.nanmax(outx), 2)
Exemplo n.º 7
0
def test_warp_clip_image_containing_nans(order):
    # Test that clipping works as intended on an image with NaNs
    # Orders 2, 4, and 5 do not produce good output when the input image has
    # NaNs, so those orders are not tested

    x = np.ones((15, 15), dtype=np.float64)
    x[7, 7] = np.nan

    outx = rotate(x, 45, order=order, cval=2, resize=True, clip=True)

    assert_array_almost_equal(np.nanmin(outx), 1)
    assert_array_almost_equal(np.nanmax(outx), 2)
Exemplo n.º 8
0
def test_warp_clip_cval_outside_input_range(order):
    # Test that clipping behavior considers cval part of the input range

    x = np.ones((15, 15), dtype=np.float64)

    # Specify a cval that is outside the input range to check clipping
    with expected_warnings(['Bi-quadratic.*bug'] if order == 2 else None):
        outx = rotate(x, 45, order=order, cval=2, resize=True, clip=True)

    # The corners should be cval for all interpolation orders
    assert_array_almost_equal([outx[0, 0], outx[0, -1],
                               outx[-1, 0], outx[-1, -1]], 2)

    # For all interpolation orders other than nearest-neighbor, the clipped
    # output should have some pixels with values between the input (1) and
    # cval (2) (i.e., clipping should not set them to 1)
    if order > 0:
        assert np.sum(np.less(1, outx) * np.less(outx, 2)) > 0
Exemplo n.º 9
0
def test_rotate_resize_90():
    x90 = rotate(np.zeros((470, 230), dtype=np.double), 90, resize=True)
    assert x90.shape == (230, 470)
Exemplo n.º 10
0
def test_rotate(dtype):
    x = np.zeros((5, 5), dtype=dtype)
    x[1, 1] = 1
    x90 = rotate(x, 90)
    assert x90.dtype == _supported_float_type(dtype)
    assert_array_almost_equal(x90, np.rot90(x))
Exemplo n.º 11
0
def test_rotate():
    x = np.zeros((5, 5), dtype=np.double)
    x[1, 1] = 1
    x90 = rotate(x, 90)
    assert_almost_equal(x90, np.rot90(x))