Example #1
0
def test_integer_perfect_recon():
    # Check that an integer input is correctly coerced into a floating point
    # array and reconstructed
    A = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=np.int32)
    Yl, Yh = dtwavexfm2(A)
    B = dtwaveifm2(Yl, Yh)
    assert np.max(np.abs(A - B)) < 1e-5
Example #2
0
def test_integer_perfect_recon():
    # Check that an integer input is correctly coerced into a floating point
    # array and reconstructed
    A = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=np.int32)
    Yl, Yh = dtwavexfm2(A)
    B = dtwaveifm2(Yl, Yh)
    assert np.max(np.abs(A - B)) < 1e-5
Example #3
0
def test_float32_input():
    # Check that an float32 input is correctly output as float32
    Yl, Yh = dtwavexfm2(lena.astype(np.float32))
    assert np.issubsctype(Yl.dtype, np.float32)
    assert np.all(list(np.issubsctype(x.dtype, np.complex64) for x in Yh))

    lena_recon = dtwaveifm2(Yl, Yh)
    assert np.issubsctype(lena_recon.dtype, np.float32)
Example #4
0
def load_and_transform_image(filename, xfmargs=None):
    """Load an image from a file named *filename* and transform it. If
    necessary the image will be transformed into luminance. *xfmargs* is a
    dictionary which is passwd as kwargs to dtwavexfm2.

    """
    log.info('Loading image from {0}'.format(filename))
    im = as_luminance(Image.open(filename)).astype(np.float32)
    return dtwavexfm2(im, **(xfmargs or {}))
Example #5
0
def load_and_transform_image(filename, xfmargs=None):
    """Load an image from a file named *filename* and transform it. If
    necessary the image will be transformed into luminance. *xfmargs* is a
    dictionary which is passwd as kwargs to dtwavexfm2.

    """
    log.info('Loading image from {0}'.format(filename))
    im = as_luminance(Image.open(filename)).astype(np.float32)
    return dtwavexfm2(im, **(xfmargs or {}))
Example #6
0
def test_simple_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena, include_scale=True)
Example #7
0
def test_3d():
    Yl, Yh = dtwavexfm2(np.dstack((lena, lena)))
Example #8
0
def test_1d():
    Yl, Yh = dtwavexfm2(lena[0, :])
Example #9
0
def test_simple_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena, include_scale=True)
Example #10
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(lena, biort=biort("antonini"), qshift=qshift("qshift_06"))
Example #11
0
def test_0_levels_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena, nlevels=0, include_scale=True)
    assert np.all(np.abs(Yl - lena) < TOLERANCE)
    assert len(Yh) == 0
    assert len(Yscale) == 0
Example #12
0
def test_odd_rows_and_cols_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena[:509, :509], include_scale=True)
Example #13
0
def test_1d():
    Yl, Yh = dtwavexfm2(lena[0, :])
Example #14
0
def test_integer_input():
    # Check that an integer input is correctly coerced into a floating point
    # array
    Yl, Yh = dtwavexfm2([[1, 2, 3, 4], [1, 2, 3, 4]])
    assert np.any(Yl != 0)
Example #15
0
def test_0_levels_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena, nlevels=0, include_scale=True)
    assert np.all(np.abs(Yl - lena) < TOLERANCE)
    assert len(Yh) == 0
    assert len(Yscale) == 0
Example #16
0
def test_0_levels():
    Yl, Yh = dtwavexfm2(lena, nlevels=0)
    assert np.all(np.abs(Yl - lena) < TOLERANCE)
    assert len(Yh) == 0
Example #17
0
def test_odd_rows_and_cols_w_scale():
    Yl, Yh, Yscale = dtwavexfm2(lena[:509, :509], include_scale=True)
Example #18
0
def test_odd_rows_and_cols():
    Yl, Yh = dtwavexfm2(lena[:, :509])
Example #19
0
def test_odd_rows():
    Yl, Yh = dtwavexfm2(lena[:509, :])
Example #20
0
def test_odd_rows():
    Yl, Yh = dtwavexfm2(lena[:509, :])
Example #21
0
def test_odd_rows_and_cols():
    Yl, Yh = dtwavexfm2(lena[:, :509])
Example #22
0
def test_reconstruct():
    # Reconstruction up to tolerance
    Yl, Yh = dtwavexfm2(lena)
    lena_recon = dtwaveifm2(Yl, Yh)
    assert np.all(np.abs(lena_recon - lena) < TOLERANCE)
Example #23
0
def test_0_levels():
    Yl, Yh = dtwavexfm2(lena, nlevels=0)
    assert np.all(np.abs(Yl - lena) < TOLERANCE)
    assert len(Yh) == 0
Example #24
0
def test_reconstruct_custom_filter():
    # Reconstruction up to tolerance
    Yl, Yh = dtwavexfm2(lena, 4, biort('legall'), qshift('qshift_06'))
    lena_recon = dtwaveifm2(Yl, Yh, biort('legall'), qshift('qshift_06'))
    assert np.all(np.abs(lena_recon - lena) < TOLERANCE)
Example #25
0
def test_integer_input():
    # Check that an integer input is correctly coerced into a floating point
    # array
    Yl, Yh = dtwavexfm2([[1, 2, 3, 4], [1, 2, 3, 4]])
    assert np.any(Yl != 0)
Example #26
0
def test_simple():
    Yl, Yh = dtwavexfm2(lena)
scale = 1.2
scale_method = 'lanczos'

def scale_direct(im):
    """Scale image directly."""
    return dtcwt.sampling.scale(im, (im.shape[0]*scale, im.shape[1]*scale), scale_method)

def scale_highpass(im):
    """Scale image assuming it to be wavelet highpass coefficients."""
    return dtcwt.sampling.scale_highpass(im, (im.shape[0]*scale, im.shape[1]*scale), scale_method)

# Rescale lena directly using default (Lanczos) sampling
lena_direct = scale_direct(lena)

# Transform lena
lena_l, lena_h = dtcwt.dtwavexfm2(lena, nlevels=4)

# Re-scale each component and transform back. Do this both with and without
# shifting back to DC.
lena_l = scale_direct(lena_l)
lena_h_a, lena_h_b = [], []

for h in lena_h:
    lena_h_a.append(scale_direct(h))
    lena_h_b.append(scale_highpass(h))

# Transform back
lena_a = dtcwt.dtwaveifm2(lena_l, lena_h_a)
lena_b = dtcwt.dtwaveifm2(lena_l, lena_h_b)

figure(figsize=(10,10))
Example #28
0
def test_3d():
    Yl, Yh = dtwavexfm2(np.dstack((lena, lena)))
Example #29
0
def test_reconstruct_crop():
    # Reconstruction up to tolerance
    Yl_crop, Yh_crop = dtwavexfm2(lena_crop)
    lena_recon = dtwaveifm2(Yl_crop, Yh_crop)[:lena_crop.shape[0], :lena_crop.shape[1]]
    assert np.all(np.abs(lena_recon - lena_crop) < TOLERANCE)
Example #30
0
def test_simple():
    Yl, Yh = dtwavexfm2(lena)
Example #31
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(lena,
                        biort=biort('antonini'),
                        qshift=qshift('qshift_06'))
    """Scale image directly."""
    return dtcwt.sampling.scale(im, (im.shape[0] * scale, im.shape[1] * scale),
                                scale_method)


def scale_highpass(im):
    """Scale image assuming it to be wavelet highpass coefficients."""
    return dtcwt.sampling.scale_highpass(
        im, (im.shape[0] * scale, im.shape[1] * scale), scale_method)


# Rescale lena directly using default (Lanczos) sampling
lena_direct = scale_direct(lena)

# Transform lena
lena_l, lena_h = dtcwt.dtwavexfm2(lena, nlevels=4)

# Re-scale each component and transform back. Do this both with and without
# shifting back to DC.
lena_l = scale_direct(lena_l)
lena_h_a, lena_h_b = [], []

for h in lena_h:
    lena_h_a.append(scale_direct(h))
    lena_h_b.append(scale_highpass(h))

# Transform back
lena_a = dtcwt.dtwaveifm2(lena_l, lena_h_a)
lena_b = dtcwt.dtwaveifm2(lena_l, lena_h_b)

figure(figsize=(10, 10))