ClearMap.ImageProcessing.Filter package

This sub-package provides various volumetric filter kernels and structure elments

A set of linear filters can be applied to the data using LinearFilter.

Because its utility for cell detection the difference of Gaussians filter is implemented directly in DoGFilter.

The fitler kernels defined in FilterKernel can be used in combination with the Convolution module.

Structured elements defined in StructureElements can be used in combination with various morphological operations, e.g. used in the :mod:~ClearMap.ImageProcessing.BackgroundRemoval` module.

ClearMap.ImageProcessing.Filter.LinearFilter module

Linear filter module

filterLinear(img, filterLinearParameter=None, ftype=None, size=None, sigma=None, sigma2=None, save=None, subStack=None, verbose=False, out=<open file '<stdout>', mode 'w'>, **parameter)[source]

Applies a linear filter to the image

Parameters:
  • img (array) – image data

  • filterLinearParameter (dict) –

    Name Type Descritption
    ftype (str or None) the type of the filter, see Filter Type if None do ot perform any fitlering
    size (tuple or None) size for the filter if None, do not perform filtering
    sigma (tuple or None) std of outer Guassian, if None autmatically determined from size
    sigma2 (tuple or None) std of inner Guassian, if None autmatically determined from size
    save (str or None) file name to save result of this operation if None dont save to file
    verbose (bool or int) print progress information
  • subStack (dict or None) – sub-stack information

  • verbose (bool) – print progress info

  • out (object) – object to write progress info to

Returns:

array – filtered image

Note

Converts image to float32 type if filter is active!

ClearMap.ImageProcessing.Filter.DoGFilter module

DoG filter module

filterDoG(img, filterDoGParameter=None, size=None, sigma=None, sigma2=None, save=None, verbose=None, subStack=None, out=<open file '<stdout>', mode 'w'>, **parameter)[source]

Difference of Gaussians (DoG) filter step

Parameters:
  • img (array) – image data

  • filterDoGParameter (dict) –

    Name Type Descritption
    size (tuple or None) size for the DoG filter if None, do not correct for any background
    sigma (tuple or None) std of outer Guassian, if None autmatically determined from size
    sigma2 (tuple or None) std of inner Guassian, if None autmatically determined from size
    save (str or None) file name to save result of this operation if None dont save to file
    verbose (bool or int) print progress information
  • subStack (dict or None) – sub-stack information

  • out (object) – object to write progress info to

Returns:

array – DoG filtered image

ClearMap.ImageProcessing.Filter.Convolution module

Convolve volumetric data with a 3d kernel, optimized for memory / float32 use

Based on scipy.signal routines.

Author

Original code from scipy.signal.

Modified by Chirstoph Kirst to optimize memory and sped and integration into ClearMap. The Rockefeller University, New York City, 2015

convolve(x, k, mode='same')[source]

Convolve array with kernel using float32 / complex64, optimized for memory consumption and speed

Parameters:
  • x (array) – data to be convolved
  • k (array) – filter kernel
Returns:

array – convolution

ClearMap.ImageProcessing.Filter.FilterKernel module

Implementation of various volumetric filter kernels

Filter Type

Filter types defined by the ftype key include:

Type Descrition
mean uniform averaging filter
gaussian Gaussian filter
log Laplacian of Gaussian filter (LoG)
dog Difference of Gaussians filter (DoG)
sphere Sphere filter
disk Disk filter
filterKernel(ftype='Gaussian', size=(5, 5), sigma=None, radius=None, sigma2=None)[source]

Creates a filter kernel of a special type

Parameters:
  • ftype (str) – filter type, see Filter Type
  • size (array or tuple) – size of the filter kernel
  • sigma (tuple or float) – std for the first gaussian (if present)
  • radius (tuple or float) – radius of the kernel (if applicable)
  • sigma2 (tuple or float) – std of a second gaussian (if present)
Returns:

array – structure element

filterKernel2D(ftype='Gaussian', size=(5, 5), sigma=None, sigma2=None, radius=None)[source]

Creates a 2d filter kernel of a special type

Parameters:
  • ftype (str) – filter type, see Filter Type
  • size (array or tuple) – size of the filter kernel
  • sigma (tuple or float) – std for the first gaussian (if present)
  • radius (tuple or float) – radius of the kernel (if applicable)
  • sigma2 (tuple or float) – std of a second gaussian (if present)
Returns:

array – structure element

filterKernel3D(ftype='Gaussian', size=(5, 5, 5), sigma=None, sigma2=None, radius=None)[source]

Creates a 3d filter kernel of a special type

Parameters:
  • ftype (str) – filter type, see Filter Type
  • size (array or tuple) – size of the filter kernel
  • sigma (tuple or float) – std for the first gaussian (if present)
  • radius (tuple or float) – radius of the kernel (if applicable)
  • sigma2 (tuple or float) – std of a second gaussian (if present)
Returns:

array – structure element

test()[source]

Test FilterKernel module

ClearMap.ImageProcessing.Filter.StructureElement module

Routines to generate various structure elements

Structured elements defined by the setype key include:

Structure Element Types

Type Descrition
sphere Sphere structure
disk Disk structure

Note

To be extended!

structureElement(setype='Disk', sesize=(3, 3))[source]

Creates specific 2d and 3d structuring elements

Parameters:
  • setype (str) – structure element type, see Structure Element Types
  • sesize (array or tuple) – size of the structure element
Returns:

array – structure element

structureElementOffsets(sesize)[source]

Calculates offsets for a structural element given its size

Parameters:sesize (array or tuple) – size of the structure element
Returns:array – offsets to center taking care of even/odd ummber of elements
structureElement2D(setype='Disk', sesize=(3, 3))[source]

Creates specific 2d structuring elements

Parameters:
  • setype (str) – structure element type, see Structure Element Types
  • sesize (array or tuple) – size of the structure element
Returns:

array – structure element

structureElement3D(setype='Disk', sesize=(3, 3, 3))[source]

Creates specific 3d structuring elements

Parameters:
  • setype (str) – structure element type, see Structure Element Types
  • sesize (array or tuple) – size of the structure element
Returns:

array – structure element