示例#1
0
文件: testxfm2.py 项目: tegale/dtcwt
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
示例#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
示例#3
0
文件: testifm2.py 项目: tegale/dtcwt
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)
示例#4
0
def inv_transform_and_save_image(filename, transform, xfmargs=None):
    """Inverse transform assuming Yl, Yh = transform passing biort and qshift
    from xfmargs to dtwaveifm2 if they are present. Save the resulting image to
    filename in PNG format.
    
    """
    im_array = dtwaveifm2(transform[0], transform[1], biort=xfmargs['biort'], qshift=xfmargs['qshift'])
    im = Image.fromarray(np.clip(im_array, 0, 255).astype(np.uint8))
    im.save(filename, format='PNG')
示例#5
0
def inv_transform_and_save_image(filename, transform, xfmargs=None):
    """Inverse transform assuming Yl, Yh = transform passing biort and qshift
    from xfmargs to dtwaveifm2 if they are present. Save the resulting image to
    filename in PNG format.
    
    """
    im_array = dtwaveifm2(transform[0],
                          transform[1],
                          biort=xfmargs['biort'],
                          qshift=xfmargs['qshift'])
    im = Image.fromarray(np.clip(im_array, 0, 255).astype(np.uint8))
    im.save(filename, format='PNG')
示例#6
0
文件: testifm2.py 项目: tegale/dtcwt
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)
示例#7
0
文件: testifm2.py 项目: tegale/dtcwt
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)
示例#8
0
文件: testifm2.py 项目: tegale/dtcwt
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)
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))

subplot(2,2,1)
imshow(lena, cmap=cm.gray, clim=(0,1), interpolation='none')
axis('off')
title('Original')

subplot(2,2,2)
imshow(lena_direct, cmap=cm.gray, clim=(0,1), interpolation='none')
axis('off')
title('Directly up-sampled')

subplot(2,2,3)
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))

subplot(2, 2, 1)
imshow(lena, cmap=cm.gray, clim=(0, 1), interpolation='none')
axis('off')
title('Original')

subplot(2, 2, 2)
imshow(lena_direct, cmap=cm.gray, clim=(0, 1), interpolation='none')
axis('off')
title('Directly up-sampled')

subplot(2, 2, 3)