Esempio n. 1
0
def test_haar():
    image = luispedro_jpg(1)
    image = image[:256,:256]
    wav = mahotas.haar(image)

    assert wav.shape == image.shape
    assert np.allclose((image[0].reshape((-1,2)).mean(1)+image[1].reshape((-1,2)).mean(1))/2, wav[0,:128]/2.)
    assert np.abs(np.mean(image**2) - np.mean(wav**2)) < 1.

    image = luispedro_jpg(1)
    wav =  mahotas.haar(image, preserve_energy=False)
    assert np.abs(np.mean(image**2) - np.mean(wav**2)) > 16.
    wav =  mahotas.haar(image, inline=True)
    assert id(image) == id(wav)
Esempio n. 2
0
def test_haar():
    image = luispedro_jpg()
    image = image[:256, :256]
    wav = mahotas.haar(image)

    assert wav.shape == image.shape
    assert np.allclose((image[0].reshape((-1, 2)).mean(1) + image[1].reshape(
        (-1, 2)).mean(1)) / 2, wav[0, :128] / 2.)
    assert np.abs(np.mean(image**2) - np.mean(wav**2)) < 1.

    image = luispedro_jpg()
    wav = mahotas.haar(image, preserve_energy=False)
    assert np.abs(np.mean(image**2) - np.mean(wav**2)) > 16.
    wav = mahotas.haar(image, inline=True)
    assert id(image) == id(wav)
Esempio n. 3
0
def test_daubechies_D2_haar():
    image = luispedro_jpg(1)
    image = image[:256,:256]
    wav = mahotas.haar(image, preserve_energy=False)
    dau = mahotas.daubechies(image, 'D2')

    assert wav.shape == dau.shape
    assert np.allclose(dau, wav)
Esempio n. 4
0
def test_daubechies_D2_haar():
    image = luispedro_jpg()
    image = image[:256, :256]
    wav = mahotas.haar(image, preserve_energy=False)
    dau = mahotas.daubechies(image, 'D2')

    assert wav.shape == dau.shape
    assert np.allclose(dau, wav)
Esempio n. 5
0
def test_ihaar():
    image = luispedro_jpg(1)
    image = image[:256,:256]
    wav = mahotas.haar(image)
    iwav = mahotas.ihaar(wav)
    assert np.allclose(image, iwav)
    iwav = mahotas.ihaar(wav, preserve_energy=False)
    assert not np.allclose(wav, iwav)
    iwav =  mahotas.ihaar(wav, inline=True)
    assert id(iwav) == id(wav)
Esempio n. 6
0
def test_ihaar():
    image = luispedro_jpg()
    image = image[:256, :256]
    wav = mahotas.haar(image)
    iwav = mahotas.ihaar(wav)
    assert np.allclose(image, iwav)
    iwav = mahotas.ihaar(wav, preserve_energy=False)
    assert not np.allclose(wav, iwav)
    iwav = mahotas.ihaar(wav, inline=True)
    assert id(iwav) == id(wav)
Esempio n. 7
0
def haar(img):
    """Haar wavelet transform."""
    # Cannot have nans here, they might have global influence.
    img = np.asarray_chkfinite(img)
    assert img.ndim == 2
    # assert img.shape[0] % 2 == img.shape[1] % 2 == 0
    # Prune possible odd borders.
    newshape = [x - x % 2 for x in img.shape]
    img = img[:newshape[0], :newshape[1]]
    a = mahotas.haar(img)
    h, w = [x // 2 for x in a.shape]
    coeffs = [a[:h, :w], a[:h, w:], a[h:, :w], a[h:, w:]]
    coeffs = [ndimage.interpolation.zoom(l, 2.) for l in coeffs]
    return coeffs