nanshe.imp.filters.wavelet module

The wavelet module provides support for performing a wavelet transform.

Overview

Included are tools to aid in the computation of the wavelet transform. In particular, construction of the kernel at different scales and it application to the data. The kernel applied is based on the technique presented by Reichinnek, et al. ( doi:10.1016/j.neuroimage.2011.12.018 ).

API

nanshe.imp.filters.wavelet.binomial_1D_array_kernel(*args, **kwargs)[source]

Generates a 1D numpy array used to make the kernel for the wavelet transform.

Parameters:
  • i (int) – which scaling to use.
  • n (int) – which row of Pascal’s triangle to return.
Returns:

a 1D numpy array to use as the wavelet

transform kernel.

Return type:

r(numpy.ndarray)

Examples

>>> binomial_1D_array_kernel(0, -2)
array([], dtype=float64)
>>> binomial_1D_array_kernel(0, 0)
array([ 1.])
>>> binomial_1D_array_kernel(0)
array([ 0.0625,  0.25  ,  0.375 ,  0.25  ,  0.0625])
>>> binomial_1D_array_kernel(0, 4)
array([ 0.0625,  0.25  ,  0.375 ,  0.25  ,  0.0625])
>>> binomial_1D_array_kernel(1, 4)
array([ 0.0625,  0.25  ,  0.375 ,  0.25  ,  0.0625])
>>> binomial_1D_array_kernel(2, 4)
array([ 0.0625,  0.    ,  0.25  ,  0.    ,  0.375 ,  0.    ,  0.25  ,
        0.    ,  0.0625])
>>> binomial_1D_array_kernel(3, 4)
array([ 0.0625,  0.    ,  0.    ,  0.    ,  0.25  ,  0.    ,  0.    ,
        0.    ,  0.375 ,  0.    ,  0.    ,  0.    ,  0.25  ,  0.    ,
        0.    ,  0.    ,  0.0625])
>>> binomial_1D_array_kernel(4, 4)
array([ 0.0625,  0.    ,  0.    ,  0.    ,  0.    ,  0.    ,  0.    ,
        0.    ,  0.25  ,  0.    ,  0.    ,  0.    ,  0.    ,  0.    ,
        0.    ,  0.    ,  0.375 ,  0.    ,  0.    ,  0.    ,  0.    ,
        0.    ,  0.    ,  0.    ,  0.25  ,  0.    ,  0.    ,  0.    ,
        0.    ,  0.    ,  0.    ,  0.    ,  0.0625])
>>> binomial_1D_array_kernel(2, 1)
array([ 0.5,  0. ,  0.5])
nanshe.imp.filters.wavelet.binomial_1D_vigra_kernel(*args, **kwargs)[source]

Generates a vigra.filters.Kernel1D using binomial_1D_array_kernel(i).

Parameters:
  • i (int) – which scaling to use.
  • n (int) – which row of Pascal’s triangle to return.
  • border_treatment (vigra.filters.BorderTreatmentMode) – determines how to deal with the borders.
Returns:

a 1D vigra

kernel to aid in computing the wavelet transform.

Return type:

k(vigra.filters.Kernel1D)

Examples

>>> binomial_1D_vigra_kernel(1) # doctest: +ELLIPSIS
<vigra.filters.Kernel1D object at 0x...>
nanshe.imp.filters.wavelet.transform(*args, **kwargs)[source]

Performs integral steps of the wavelet transform on im0 up to the given scale. If scale is an iterable, then

Parameters:
  • im0 (numpy.ndarray) – the original image.
  • scale (int or tuple of ints) – the scale of wavelet transform to apply.
  • include_intermediates (bool) – whether to return intermediates or not (default False).
  • include_lower_scales (bool) – whether to include lower scales or not (default False) (ignored if include_intermediates is True)
  • out (numpy.ndarray) – holds final result (cannot use unless include_intermediates is False or an AssertionError will be raised.)
Returns:

returns the final result of

the wavelet transform and possibly other scales. Also, may return the intermediates.

Return type:

W, out(tuple of numpy.ndarrays)

Examples

>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = True,
...     include_lower_scales = True) # doctest: +NORMALIZE_WHITESPACE
(array([[[ 0.59375, -0.375  , -0.34375],
         [-0.375  ,  0.625  , -0.375  ],
         [-0.34375, -0.375  ,  0.59375]]], dtype=float32),
 array([[[ 1.     ,  0.     ,  0.     ],
         [ 0.     ,  1.     ,  0.     ],
         [ 0.     ,  0.     ,  1.     ]],
        [[ 0.40625,  0.375  ,  0.34375],
         [ 0.375  ,  0.375  ,  0.375  ],
         [ 0.34375,  0.375  ,  0.40625]]], dtype=float32))
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = True)
array([[[ 0.59375, -0.375  , -0.34375],
        [-0.375  ,  0.625  , -0.375  ],
        [-0.34375, -0.375  ,  0.59375]]], dtype=float32)
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = False)
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = (0, 1),
...     include_intermediates = False,
...     include_lower_scales = False)
array([[ 0.625, -0.25 , -0.125],
       [-0.5  ,  0.5  , -0.5  ],
       [-0.125, -0.25 ,  0.625]], dtype=float32)
>>> out = numpy.zeros((3, 3), dtype = numpy.float32)
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = False,
...     out = out)
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> out
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> out = numpy.eye(3, dtype = numpy.float32)
>>> transform(out,
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = False,
...     out = out)
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> out
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> out = numpy.empty((1, 3, 3), dtype = numpy.float32)
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = True,
...     out = out) # doctest: +NORMALIZE_WHITESPACE
array([[[ 0.59375, -0.375  , -0.34375],
        [-0.375  ,  0.625  , -0.375  ],
        [-0.34375, -0.375  ,  0.59375]]], dtype=float32)
>>> out
array([[[ 0.59375, -0.375  , -0.34375],
        [-0.375  ,  0.625  , -0.375  ],
        [-0.34375, -0.375  ,  0.59375]]], dtype=float32)
>>> out = numpy.empty((1, 3, 3), dtype = numpy.float64)
>>> transform(numpy.eye(3, dtype = numpy.float32),
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = True,
...     out = out) # doctest: +NORMALIZE_WHITESPACE
array([[[ 0.59375, -0.375  , -0.34375],
        [-0.375  ,  0.625  , -0.375  ],
        [-0.34375, -0.375  ,  0.59375]]])
>>> out
array([[[ 0.59375, -0.375  , -0.34375],
        [-0.375  ,  0.625  , -0.375  ],
        [-0.34375, -0.375  ,  0.59375]]])
>>> out = numpy.eye(3, dtype = numpy.uint8)
>>> transform(out,
...     scale = 1,
...     include_intermediates = False,
...     include_lower_scales = False,
...     out = out)
array([[ 0.59375, -0.375  , -0.34375],
       [-0.375  ,  0.625  , -0.375  ],
       [-0.34375, -0.375  ,  0.59375]], dtype=float32)
>>> out
array([[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1]], dtype=uint8)