예제 #1
0
def test_pyramid_expand_rgb_deprecated_multichannel():
    rows, cols, dim = image.shape
    with expected_warnings(["`multichannel` is a deprecated argument"]):
        out = pyramids.pyramid_expand(image, upscale=2, multichannel=True)
    assert_array_equal(out.shape, (rows * 2, cols * 2, dim))

    # repeat prior test, but check for positional multichannel warning
    with expected_warnings(["Providing the `multichannel` argument"]):
        out = pyramids.pyramid_expand(image, 2, None, 1, 'reflect', 0, True)
    assert_array_equal(out.shape, (rows * 2, cols * 2, dim))
예제 #2
0
def test_pyramid_expand_nd():
    for ndim in [1, 2, 3, 4]:
        img = np.random.randn(*((4, ) * ndim))
        out = pyramids.pyramid_expand(img, upscale=2,
                                      multichannel=False)
        expected_shape = np.asarray(img.shape) * 2
        assert_array_equal(out.shape, expected_shape)
예제 #3
0
파일: image.py 프로젝트: silky/deepdish
def resize_by_factor(im, factor):
    """
    Resizes the image according to a factor. The image is pre-filtered
    with a Gaussian and then resampled with bilinear interpolation.

    This function uses scikit-image and essentially combines its
    `pyramid_reduce` with `pyramid_expand` into one function.

    Returns the same object if factor is 1, not a copy.

    Parameters
    ----------
    im : ndarray, ndim=2 or 3
        Image. Either 2D or 3D with 3 or 4 channels.
    factor : float
        Resize factor, e.g. a factor of 0.5 will halve both sides.
    """
    _import_skimage()
    from skimage.transform.pyramids import pyramid_reduce, pyramid_expand
    if factor < 1:
        return pyramid_reduce(im, downscale=1/factor)
    elif factor > 1:
        return pyramid_expand(im, upscale=factor)
    else:
        return im
예제 #4
0
def test_pyramid_expand_nd():
    for ndim in [1, 2, 3, 4]:
        img = np.random.randn(*((4, ) * ndim))
        out = pyramids.pyramid_expand(img, upscale=2,
                                      multichannel=False)
        expected_shape = np.asarray(img.shape) * 2
        assert_array_equal(out.shape, expected_shape)
예제 #5
0
def resize_by_factor(im, factor):
    """
    Resizes the image according to a factor. The image is pre-filtered
    with a Gaussian and then resampled with bilinear interpolation.

    This function uses scikit-image and essentially combines its
    `pyramid_reduce` with `pyramid_expand` into one function.

    Returns the same object if factor is 1, not a copy.

    Parameters
    ----------
    im : ndarray, ndim=2 or 3
        Image. Either 2D or 3D with 3 or 4 channels.
    factor : float
        Resize factor, e.g. a factor of 0.5 will halve both sides.
    """
    _import_skimage()
    from skimage.transform.pyramids import pyramid_reduce, pyramid_expand
    if factor < 1:
        return pyramid_reduce(im, downscale=1 / factor)
    elif factor > 1:
        return pyramid_expand(im, upscale=factor)
    else:
        return im
예제 #6
0
파일: img.py 프로젝트: EdwardBetts/partsNet
def resize_with_factor_new(im, factor):
    if factor < 1 - 1e-8:
        im2 = pyramid_reduce(im, downscale=1/factor)
    elif factor > 1 + 1e-8:
        im2 = pyramid_expand(im, upscale=factor)
    else:
        im2 = im.copy()
    return im2
예제 #7
0
def test_pyramid_expand_rgb(channel_axis):
    image = data.astronaut()
    rows, cols, dim = image.shape
    image = np.moveaxis(image, source=-1, destination=channel_axis)
    out = pyramids.pyramid_expand(image, upscale=2, channel_axis=channel_axis)
    expected_shape = [rows * 2, cols * 2]
    expected_shape.insert(channel_axis % image.ndim, dim)
    assert_array_equal(out.shape, expected_shape)
예제 #8
0
def resize_with_factor_new(im, factor):
    if factor < 1 - 1e-8:
        im2 = pyramid_reduce(im, downscale=1 / factor)
    elif factor > 1 + 1e-8:
        im2 = pyramid_expand(im, upscale=factor)
    else:
        im2 = im.copy()
    return im2
예제 #9
0
def resize(im, f):
    if f < 1:
        im2 = pyramid_reduce(im, downscale=1/f)
    elif f > 1:
        im2 = pyramid_expand(im, upscale=f)
    else:
        im2 = im
    return im2
예제 #10
0
파일: img.py 프로젝트: EdwardBetts/partsNet
def resize(im, new_size, preserve_aspect_ratio=True, prefilter=True):
    """
    This is a not-very-rigorous function to do image resizing, with
    pre-filtering.
    """
    factors = [new_size[i] / im.shape[i] for i in range(2)]

    #assert factors[0] == factors[1], "Must have same factor for now"
    f = factors[0] 
    
    if f < 1:
        im2 = pyramid_reduce(im, downscale=1/f)
    elif f > 1:
        im2 = pyramid_expand(im, upscale=f)
    else:
        im2 = im

    assert im2.shape[:2] == tuple(new_size), "{0} != {1} (original size: {2})".format(im2.shape, new_size, im.shape)
     
    return im2
예제 #11
0
def resize(im, new_size, preserve_aspect_ratio=True, prefilter=True):
    """
    This is a not-very-rigorous function to do image resizing, with
    pre-filtering.
    """
    factors = [new_size[i] / im.shape[i] for i in range(2)]

    #assert factors[0] == factors[1], "Must have same factor for now"
    f = factors[0]

    if f < 1:
        im2 = pyramid_reduce(im, downscale=1 / f)
    elif f > 1:
        im2 = pyramid_expand(im, upscale=f)
    else:
        im2 = im

    assert im2.shape[:2] == tuple(
        new_size), "{0} != {1} (original size: {2})".format(
            im2.shape, new_size, im.shape)

    return im2
예제 #12
0
def test_pyramid_expand_rgb():
    rows, cols, dim = image.shape
    out = pyramids.pyramid_expand(image, upscale=2, channel_axis=-1)
    assert_array_equal(out.shape, (rows * 2, cols * 2, dim))
예제 #13
0
def test_pyramid_expand_gray():
    rows, cols = image_gray.shape
    out = pyramids.pyramid_expand(image_gray, upscale=2)
    assert_array_equal(out.shape, (rows * 2, cols * 2))
예제 #14
0
def test_pyramid_expand_gray():
    rows, cols = image_gray.shape
    with expected_warnings(['The default multichannel']):
        out = pyramids.pyramid_expand(image_gray, upscale=2)
    assert_array_equal(out.shape, (rows * 2, cols * 2))
예제 #15
0
def test_pyramid_expand_rgb():
    rows, cols, dim = image.shape
    out = pyramids.pyramid_expand(image, upscale=2)
    assert_array_equal(out.shape, (rows * 2, cols * 2, dim))
예제 #16
0
def test_pyramid_expand_gray():
    rows, cols = image_gray.shape
    out = pyramids.pyramid_expand(image_gray, upscale=2, channel_axis=None)
    assert_array_equal(out.shape, (rows * 2, cols * 2))
예제 #17
0
def test_pyramid_expand_gray():
    rows, cols = image_gray.shape
    with expected_warnings(['The default multichannel']):
        out = pyramids.pyramid_expand(image_gray, upscale=2)
    assert_array_equal(out.shape, (rows * 2, cols * 2))