Esempio n. 1
0
def test_soft_threhold():
    from mahotas.thresholding import soft_threshold

    np.random.seed(223)
    for i in range(4):
        f = np.random.randint(-256,256, size=(128,128,4))
        fo = f.copy()
        t = soft_threshold(f, 16)

        assert not np.all(fo == t)
        assert np.all(t[np.abs(f) < 16] == 0)
        assert t.max() == f.max()-16
        assert t.min() == f.min()+16
        assert np.all( (np.abs(f) <= 16) | (np.abs(f)-16 == np.abs(t)))
Esempio n. 2
0
def test_soft_threhold():
    from mahotas.thresholding import soft_threshold

    np.random.seed(223)
    for i in range(4):
        f = np.random.randint(-256, 256, size=(128, 128, 4))
        fo = f.copy()
        t = soft_threshold(f, 16)

        assert not np.all(fo == t)
        assert np.all(t[np.abs(f) < 16] == 0)
        assert t.max() == f.max() - 16
        assert t.min() == f.min() + 16
        assert np.all((np.abs(f) <= 16) | (np.abs(f) - 16 == np.abs(t)))
Esempio n. 3
0
direct = f[::2, ::2].copy()
direct /= 8
direct = direct.astype(np.uint8)
print("Fraction of zeros in original image (after division by 8):",
      np.mean(direct == 0))
plt.imshow(direct)

# Transform using D8 Wavelet to obtain transformed image t:
t = mahotas.daubechies(f, 'D8')
plt.imshow(t)

# Discard low-order bits:
t /= 8
t = t.astype(np.int8)
print("Fraction of zeros in transform (after division by 8):", np.mean(t == 0))
plt.imshow(t)

# Let us look at what this looks like
r = mahotas.idaubechies(t, 'D8')
plt.imshow(r)

# Go further, discard small values in the transformed space:
tt = soft_threshold(t, 12)
print(
    "Fraction of zeros in transform (after division by 8 & soft thresholding):",
    np.mean(tt == 0))

# Let us look again at what we have:
rt = mahotas.idaubechies(tt, 'D8')
plt.imshow(rt)
Esempio n. 4
0
# A baseline compression method: save every other pixel and only high-order bits:
direct = f[::2,::2].copy()
direct /= 8
direct = direct.astype(np.uint8)
print("Fraction of zeros in original image (after division by 8):", np.mean(direct==0))
plt.imshow(direct)


# Transform using D8 Wavelet to obtain transformed image t:
t = mahotas.daubechies(f,'D8')
plt.imshow(t)

# Discard low-order bits:
t /= 8
t = t.astype(np.int8)
print("Fraction of zeros in transform (after division by 8):", np.mean(t==0))
plt.imshow(t)

# Let us look at what this looks like
r = mahotas.idaubechies(t, 'D8')
plt.imshow(r)

# Go further, discard small values in the transformed space:
tt = soft_threshold(t, 12)
print("Fraction of zeros in transform (after division by 8 & soft thresholding):", np.mean(tt==0))

# Let us look again at what we have:
rt = mahotas.idaubechies(tt, 'D8')
plt.imshow(rt)