nanshe.imp.renorm module

The renorm module provides ways to standardize frames of an image stack.

Overview

The renorm (or renormalization) module provides a few simple utility methods for standardizing a set of images. The first is to recompute each frame so that its mean is 0. The second is to normalize each frame using an appropriate Lp norm. Both have the ability of working in-place.

API

nanshe.imp.renorm.renormalized_images(*args, **kwargs)[source]

Takes and divide each image by its norm. Where each image is new_numpy_array[i] with some index i.

Parameters:
  • new_numpy_array (numpy.ndarray) – array images with time as the first index
  • ord (int) – Which norm to use. (L_2 or Euclidean is default)
  • output_array (numpy.ndarray) – provides a location to store the result (optional)
Returns:

The same array with each images

normalized.

Return type:

result(numpy.ndarray)

Examples

>>> renormalized_images(numpy.array([[0.,1.],[1.,0.]]))
array([[ 0.,  1.],
       [ 1.,  0.]])
>>> renormalized_images(
...     numpy.array([[0,1],[1,0]])
... ) #doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
AssertionError
>>> renormalized_images(
...     numpy.array([[0,1],[1,0]], dtype=numpy.float32)
... )
array([[ 0.,  1.],
       [ 1.,  0.]], dtype=float32)
>>> renormalized_images(numpy.array([[0.,2.],[1.,0.]]))
array([[ 0.,  1.],
       [ 1.,  0.]])
>>> renormalized_images(numpy.array([[2.,2.],[1.,0.]]))
array([[ 0.70710678,  0.70710678],
       [ 1.        ,  0.        ]])
>>> renormalized_images(numpy.array([[1.,2.],[3.,4.]]))
array([[ 0.4472136 ,  0.89442719],
       [ 0.6       ,  0.8       ]])
>>> renormalized_images(numpy.array([[1.,2.],[3.,4.]]), ord=1)
array([[ 0.33333333,  0.66666667],
       [ 0.42857143,  0.57142857]])
>>> a = numpy.array([[1.,2.],[3.,4.]])
>>> numpy.all(a != renormalized_images(a))
True
>>> a = numpy.array([[1.,2.],[3.,4.]])
>>> numpy.all(a == renormalized_images(a, output_array=a))
True
>>> a = numpy.array([[1.,2.],[3.,4.]]); b = numpy.zeros_like(a)
>>> numpy.all(b == renormalized_images(a, output_array=b))
True
>>> renormalized_images(numpy.zeros((2,3,)))
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.]])
nanshe.imp.renorm.zeroed_mean_images(*args, **kwargs)[source]

Takes and finds the mean for each image. Where each image is new_numpy_array[i] with some index i.

Parameters:
  • new_numpy_array (numpy.ndarray) – array images with time as the first index
  • output_array (numpy.ndarray) – provides a location to store the result (optional)
Returns:

The same array with each images

mean removed. Where means[i] = mean(new_numpy_array[i])

Return type:

result(numpy.ndarray)

Examples

>>> zeroed_mean_images(numpy.array([[0.,0.],[0.,0.]]))
array([[ 0.,  0.],
       [ 0.,  0.]])
>>> zeroed_mean_images(numpy.array([[6.,0.],[0.,0.]]))
array([[ 3., -3.],
       [ 0.,  0.]])
>>> zeroed_mean_images(numpy.array([[0.,0.],[0.,4.]]))
array([[ 0.,  0.],
       [-2.,  2.]])
>>> zeroed_mean_images(numpy.array([[6.,0],[0.,4.]]))
array([[ 3., -3.],
       [-2.,  2.]])
>>> zeroed_mean_images(numpy.array([[1.,2.],[3.,4.]]))
array([[-0.5,  0.5],
       [-0.5,  0.5]])
>>> zeroed_mean_images(
...     numpy.array([[1,2],[3,4]])
... ) #doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
AssertionError
>>> a = numpy.array([[1.,2.],[3.,4.]])
>>> zeroed_mean_images(a, output_array=a)
array([[-0.5,  0.5],
       [-0.5,  0.5]])
>>> a
array([[-0.5,  0.5],
       [-0.5,  0.5]])
>>> a = numpy.array([[1.,2.],[3.,4.]]); b = numpy.zeros_like(a)
>>> zeroed_mean_images(a, output_array=b)
array([[-0.5,  0.5],
       [-0.5,  0.5]])
>>> b
array([[-0.5,  0.5],
       [-0.5,  0.5]])
>>> zeroed_mean_images(
...     numpy.array([[1,2],[3,4]]).astype(numpy.float32)
... )
array([[-0.5,  0.5],
       [-0.5,  0.5]], dtype=float32)
>>> a = numpy.array([[1.,2.],[3.,4.]])
>>> numpy.all(a != zeroed_mean_images(a))
True
>>> a = numpy.array([[1.,2.],[3.,4.]])
>>> numpy.all(a == zeroed_mean_images(a, output_array=a))
True