zeabrah’s lair

7 February, 2011

A’trous 2D wavelet decomposition in python using SciPy

Filed under: dev — Tags: , , — alexeybrazhe @ 7:21 pm

Simple 2D A’trous wavelet decomposition using B3 spline in python with SciPy:

_b3spline1d = np.array([1./16, 1./4, 3./8, 1./4, 1./16])
__x = _b3spline1d.reshape(1,-1)
_b3spl2d = np.dot(__x.T,__x)

def atrous2d(arr, lev, kernel=_b3spl2d, boundary='symm'):
    "Do 2d a'trous wavelet transform with B3-spline scaling function"
    approx = signal.convolve2d(arr, kernel,
                               mode='same',
                               boundary=boundary)  # approximation
    w = arr - approx                               # wavelet details
    if lev <= 0: return arr
    if lev == 1: return [w, approx]
    else:        return [w] + atrous1(approx,lev-1, upscale(kernel), boundary)

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.