Example #1
0
	def process(self, rgb_img):

		img = utils.image.rgb2ihls(rgb_img)
		
		f = {}
		channels = {'H' : img[:,:,0], 'S' : img[:,:,1], 'Y' : img[:,:,2]}

		# For each channel
		for c, img in channels.items() :
			
			# Initiate aggregate over all levels
			f[c+"_sum"] = 0.0

			# For each wavelet level
			for l in xrange(3) :
				dimg = mahotas.daubechies(img, 'D8')

				h, w = dimg.shape
				mh, mw = h/2, w/2

				w_lh = np.mean(np.abs(dimg[:mh,mw:]))
				w_hh = np.mean(np.abs(dimg[mh:,mw:]))
				w_hl = np.mean(np.abs(dimg[mh:,:mw]))

				# Store the value in the correct name and sum the aggregate over all levels
				w = (w_lh + w_hl + w_hh)/3 
				f[c+str(l)]  = w
				f[c+"_sum"] += w

				img = img[:mh,:mw]
			
		return f
Example #2
0
def test_daubechies_idaubechies():
    f = luispedro_jpg(1)
    f = f[:256,:256]
    fo = f.copy()

    d = mahotas.daubechies(f, 'D8')
    r = mahotas.idaubechies(d, 'D8')
    assert np.mean( (r[4:-4,4:-4] - fo[4:-4,4:-4])**2) < 1.
Example #3
0
def test_wavelets_inline():
    def inline(f):
        im = np.arange(16, dtype=float).reshape((4,4))
        t = f(im, inline=True)
        assert id(im) == id(t)

    yield inline, mahotas.haar
    yield inline, lambda im,inline: mahotas.daubechies(im, 'D4', inline=inline)
Example #4
0
def test_3d_wavelets_error():
    @raises(ValueError)
    def call_f(f):
        f(np.arange(4*4*4).reshape((4,4,4)))

    yield call_f, mahotas.haar
    yield call_f, mahotas.ihaar
    yield call_f, lambda im: mahotas.daubechies(im, 'D4')
Example #5
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)
Example #6
0
def test_daubechies_idaubechies():
    f = luispedro_jpg()
    f = f[:256, :256]
    fo = f.copy()

    d = mahotas.daubechies(f, 'D8')
    r = mahotas.idaubechies(d, 'D8')
    assert np.mean((r[4:-4, 4:-4] - fo[4:-4, 4:-4])**2) < 1.
Example #7
0
def test_3d_wavelets_error():
    @raises(ValueError)
    def call_f(f):
        f(np.arange(4 * 4 * 4).reshape((4, 4, 4)))

    yield call_f, mahotas.haar
    yield call_f, mahotas.ihaar
    yield call_f, lambda im: mahotas.daubechies(im, 'D4')
Example #8
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)
Example #9
0
def test_wavelets_inline():
    def inline(f):
        im = np.arange(16, dtype=float).reshape((4, 4))
        t = f(im, inline=True)
        assert id(im) == id(t)

    yield inline, mahotas.haar
    yield inline, lambda im, inline: mahotas.daubechies(
        im, 'D4', inline=inline)
Example #10
0
def test_center_wavelet_iwavelet_decenter():
    from mahotas import wavelet_center, wavelet_decenter
    import mahotas
    import numpy as np

    f = luispedro_jpg(1)
    f = f[:100,:250]
    fo = f.copy()

    for wav in ('D2', 'D4', 'D6', 'D8', 'D10', 'D12', 'D16'):
        fc = mahotas.wavelet_center(fo, border=24)
        t = mahotas.daubechies(fc, wav)
        r = mahotas.idaubechies(t, wav)
        rd = mahotas.wavelet_decenter(r, fo.shape, border=24)
        assert np.allclose(fo, rd)
Example #11
0
def test_center_wavelet_iwavelet_decenter():
    from mahotas import wavelet_center, wavelet_decenter
    import mahotas
    import numpy as np

    f = luispedro_jpg()
    f = f[:100, :250]
    fo = f.copy()

    for wav in ('D2', 'D4', 'D6', 'D8', 'D10', 'D12', 'D16'):
        fc = mahotas.wavelet_center(fo, border=24)
        t = mahotas.daubechies(fc, wav)
        r = mahotas.idaubechies(t, wav)
        rd = mahotas.wavelet_decenter(r, fo.shape, border=24)
        assert np.allclose(fo, rd)
Example #12
0
def test_non_valid_daubechies():
    image = luispedro_jpg()
    mahotas.daubechies(image, 'D-4')
def test_non_valid_daubechies():
    image = luispedro_jpg()
    mahotas.daubechies(image, 'D-4')
Example #14
0
f = f[:256, :256]
plt.gray()
# Show the data:
plt.imshow(f)
print("Fraction of zeros in original image:", np.mean(f == 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(
Example #15
0
f = f[:256,:256]
plt.gray()
# Show the data:
plt.imshow(f)
print("Fraction of zeros in original image:", np.mean(f==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))