コード例 #1
0
ファイル: daubechies.py プロジェクト: luamct/WebSci14
	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
コード例 #2
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
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.
コード例 #3
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
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)
コード例 #4
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
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')
コード例 #5
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
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)
コード例 #6
0
ファイル: test_convolve.py プロジェクト: jayrambhia/mahotas
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.
コード例 #7
0
ファイル: test_convolve.py プロジェクト: jayrambhia/mahotas
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')
コード例 #8
0
ファイル: test_convolve.py プロジェクト: jayrambhia/mahotas
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)
コード例 #9
0
ファイル: test_convolve.py プロジェクト: jayrambhia/mahotas
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)
コード例 #10
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
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)
コード例 #11
0
ファイル: test_convolve.py プロジェクト: jayrambhia/mahotas
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)
コード例 #12
0
ファイル: test_convolve.py プロジェクト: BLKStone/mahotas
def test_non_valid_daubechies():
    image = luispedro_jpg()
    mahotas.daubechies(image, 'D-4')
コード例 #13
0
def test_non_valid_daubechies():
    image = luispedro_jpg()
    mahotas.daubechies(image, 'D-4')
コード例 #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(
コード例 #15
0
ファイル: wavelet_compress.py プロジェクト: BLKStone/mahotas
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))