Full API Documentation

A package for computer vision in Python.

Main Features

features
Compute global and local features (several submodules, include SURF and Haralick features)
convolve
Convolution and wavelets
morph
Morphological features. Most are available at the mahotas level, include erode(), dilate()...
watershed
Seeded watershed implementation
imread/imsave
read/write image

Citation:

Coelho, Luis Pedro, 2013. Mahotas: Open source software for scriptable computer vision. Journal of Open Research Software, 1:e3, DOI: http://dx.doi.org/10.5334/jors.ac
mahotas.as_rgb(r, g, b)

Returns an RGB image

If any of the channels is None, that channel is set to zero.

Parameters :

r,g,b : array-like, optional

The channels can be of any type or None. At least one must be not None and all must have the same shape.

Returns :

rgb : ndarray

RGB ndarray

mahotas.bbox(img)

Calculate the bounding box of image img.

Parameters :

img : ndarray

Any integer image type

Returns :

min1,max1,min2,max2 : int,int,int,int

These are such that img[min1:max1, min2:max2] contains all non-zero pixels

mahotas.border(labeled, i, j, Bc={3x3 cross}, out={np.zeros(labeled.shape, bool)}, always_return=True)

Compute the border region between i and j regions.

A pixel is on the border if it has value i (or j) and a pixel in its neighbourhood (defined by Bc) has value j (or i).

Parameters :

labeled : ndarray of integer type

input labeled array

i : integer

j : integer

Bc : structure element, optional

out : ndarray of same shape as labeled, dtype=bool, optional

where to store the output. If None, a new array is allocated

always_return : bool, optional

if false, then, in the case where there is no pixel on the border, returns None. Otherwise (the default), it always returns an array even if it is empty.

Returns :

border_img : boolean ndarray

Pixels are True exactly where there is a border between i and j in labeled

mahotas.borders(labeled, Bc={3x3 cross}, out={np.zeros(labeled.shape, bool)})

Compute border pixels

A pixel is on a border if it has value i and a pixel in its neighbourhood (defined by Bc) has value j, with i != j.

Parameters :

labeled : ndarray of integer type

input labeled array

Bc : structure element, optional

out : ndarray of same shape as labeled, dtype=bool, optional

where to store the output. If None, a new array is allocated

mode : {‘reflect’, ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’ [default], ‘ignore’}

How to handle borders

Returns :

border_img : boolean ndarray

Pixels are True exactly where there is a border in labeled

mahotas.bwperim(bw, n=4)

Find the perimeter of objects in binary images.

A pixel is part of an object perimeter if its value is one and there is at least one zero-valued pixel in its neighborhood.

By default the neighborhood of a pixel is 4 nearest pixels, but if n is set to 8 the 8 nearest pixels will be considered.

Parameters :

bw : ndarray

A black-and-white image (any other image will be converted to black & white)

n : int, optional

Connectivity. Must be 4 or 8 (default: 4)

mode : {‘reflect’, ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’ [default], ‘ignore’}

How to handle borders

Returns :

perim : ndarray

A boolean image

See also

borders
function This is a more generic function
mahotas.cdilate(f, g, Bc={3x3 cross}, n=1)

Conditional dilation

cdilate creates the image y by dilating the image f by the structuring element Bc conditionally to the image g. This operator may be applied recursively n times.

Parameters :

f : Gray-scale (uint8 or uint16) or binary image.

g : Conditioning image. (Gray-scale or binary).

Bc : Structuring element (default: 3x3 cross)

n : Number of iterations (default: 1)

Returns :

y : Image

mahotas.center_of_mass(img, labels=None) x0, x1, ... = center_of_mass(img, labels=None)

Returns the center of mass of img.

If labels is given, then it returns L centers of mass, one for each region identified by labels (including region 0).

Parameters :

img : ndarray

labels : ndarray

A labeled array

Returns :

coords : ndarray

if not labels, a 1-ndarray of coordinates (size = len(img.shape)), if labels, a 2-ndarray of coordinates (shape = (labels.max()+1) xlen(img.shape))

mahotas.cerode(f, g, Bc={3x3 cross}, out={np.empty_as(A)})

Conditional morphological erosion.

The type of operation depends on the dtype of A! If boolean, then the erosion is binary, else it is greyscale erosion. In the case of greyscale erosion, the smallest value in the domain of Bc is interpreted as -Inf.

Parameters :

f : ndarray

input image

g : ndarray

conditional image

Bc : ndarray, optional

Structuring element. By default, use a cross (see get_structuring_elem for details on the default).

Returns :

conditionally_eroded : ndarray

eroded version of f conditioned on g

See also

erode
function Unconditional version of this function

dilate

mahotas.close(f, Bc={3x3 cross}, out={np.empty_like(f)})

Morphological closing.

close creates the image y by the morphological closing of the image f by the structuring element Bc. In the binary case, the closing by a structuring element Bc may be interpreted as the intersection of all the binary images that contain the image f and have a hole equal to a translation of Bc. In the gray-scale case, there is a similar interpretation taking the functions umbra.

Parameters :

f : ndarray

Gray-scale (uint8 or uint16) or binary image.

Bc : ndarray, optional

Structuring element. (Default: 3x3 elementary cross).

out : ndarray, optional

Output array

Returns :

y : ndarray

See also

open
function
mahotas.close_holes(ref, Bc=None)

closed = close_holes(ref, Bc=None):

Close Holes

Parameters :

ref : ndarray

Reference image. This should be a binary image.

Bc : structuring element, optional

Default: 3x3 cross

Returns :

closed : ndarray

superset of ref (i.e. with closed holes)

mahotas.convolve(f, weights, mode='reflect', cval=0.0, out={new array})

Convolution of f and weights

Convolution is performed in doubles to avoid over/underflow, but the result is then cast to f.dtype.

Parameters :

f : ndarray

input. Any dimension is supported

weights : ndarray

weight filter. If not of the same dtype as f, it is cast

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as f as well as be C-contiguous.

Returns :

convolved : ndarray of same dtype as f

mahotas.convolve1d(f, weights, axis, mode='reflect', cval=0.0, out={new array})

Convolution of f and weights along axis axis.

Convolution is performed in doubles to avoid over/underflow, but the result is then cast to f.dtype.

Parameters :

f : ndarray

input. Any dimension is supported

weights : 1-D ndarray

weight filter. If not of the same dtype as f, it is cast

axis : int

Axis along which to convolve

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as f as well as be C-contiguous.

Returns :

convolved : ndarray of same dtype as f

See also

convolve
function generic convolution
mahotas.croptobbox(img, border=0)

Returns a version of img cropped to the image’s bounding box

Parameters :

img : ndarray

Integer image array

border : int, optional

whether to add a border (default no border)

Returns :

nimg : ndarray

A subimage of img.

mahotas.cwatershed(surface, markers, Bc=None, return_lines=False) W, WL = cwatershed(surface, markers, Bc=None, return_lines=True)

Seeded Watershed

Parameters :

surface : image

markers : image

initial markers (must be a labeled image)

Bc : ndarray, optional

structuring element (default: 3x3 cross)

return_lines : boolean, optional

whether to return separating lines (in addition to regions)

Returns :

W : Regions image (i.e., W[i,j] == region for pixel (i,j))

WL : Lines image (if return_lines==True)

mahotas.daubechies(f, code, inline=False)

Daubechies wavelet transform

This function works best if the image sizes are powers of 2!

Parameters :

f : ndarray

2-D image

code : str

One of ‘D2’, ‘D4’, ... ‘D20’

inline : bool, optional

Whether to write the results to the input image. By default, a new image is returned. Integer images are always converted to floating point and copied.

See also

haar
function Haar transform (equivalent to D2)
mahotas.dilate(A, Bc={3x3 cross}, out={np.empty_like(A)})

Morphological dilation.

The type of operation depends on the dtype of A! If boolean, then the dilation is binary, else it is greyscale dilation. In the case of greyscale dilation, the smallest value in the domain of Bc is interpreted as +Inf.

Parameters :

A : ndarray of bools

input array

Bc : ndarray, optional

Structuring element. By default, use a cross (see get_structuring_elem for details on the default).

Returns :

dilated : ndarray

dilated version of A

See also

erode

mahotas.distance(bw, metric='euclidean2')

Computes the distance transform of image bw:

dmap[i,j] = min_{i', j'} { (i-i')**2 + (j-j')**2 | !bw[i', j'] }

That is, at each point, compute the distance to the background.

If there is no background, then a very high value will be returned in all pixels (this is a sort of infinity).

Parameters :

bw : 2d-ndarray

If boolean, False will denote the background and True the foreground. If not boolean, this will be interpreted as bw != 0 (this way you can use labeled images without any problems).

metric : str, optional

one of ‘euclidean2’ (default) or ‘euclidean’

Returns :

dmap : ndarray

distance map

mahotas.erode(A, Bc={3x3 cross}, out={np.empty_as(A)})

Morphological erosion.

The type of operation depends on the dtype of A! If boolean, then the erosion is binary, else it is greyscale erosion. In the case of greyscale erosion, the smallest value in the domain of Bc is interpreted as -Inf.

Parameters :

A : ndarray

input image

Bc : ndarray, optional

Structuring element. By default, use a cross (see get_structuring_elem for details on the default).

out : ndarray, optional

output array. If used, this must be a C-array of the same dtype as A. Otherwise, a new array is allocated.

Returns :

erosion : ndarray

eroded version of A

See also

dilate

mahotas.euler(f, n=8)

Compute the Euler number of image f

The Euler number is also known as the Euler characteristic given that many other mathematical objects are also known as Euler numbers.

Parameters :

f : ndarray

A 2-D binary image

n : int, optional

Connectivity, one of (4,8). default: 8

mode : {‘reflect’, ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’ [default]}

How to handle borders

Returns :

euler_nr : int

Euler number

mahotas.fullhistogram(img)

Return a histogram with bins 0, 1, ..., ``img.max()``.

After calling this function, it will be true that hist[i] == (img == i).sum(), for all i.

Parameters :

img : array-like of an unsigned type

input image.

Returns :

hist : an dnarray of type np.uint32

This will be of size img.max() + 1.

mahotas.gaussian_filter(array, sigma, order=0, mode='reflect', cval=0., out={np.empty_like(array)})

Multi-dimensional Gaussian filter.

Parameters :

array : ndarray

input array, any dimension is supported. If the array is an integer array, it will be converted to a double array.

sigma : scalar or sequence of scalars

standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.

order : {0, 1, 2, 3} or sequence from same set, optional

The order of the filter along each axis is given as a sequence of integers, or as a single number. An order of 0 corresponds to convolution with a Gaussian kernel. An order of 1, 2, or 3 corresponds to convolution with the first, second or third derivatives of a Gaussian. Higher order derivatives are not implemented

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape as array as well as be C-contiguous. If array is an integer array, this must be a double array; otherwise, it must have the same type as array.

Returns :

filtered : ndarray

Filtered version of array

Notes

The multi-dimensional filter is implemented as a sequence of one-dimensional convolution filters. The intermediate arrays are stored in the same data type as the output. Therefore, for output types with a limited precision, the results may be imprecise because intermediate results may be stored with insufficient precision.

mahotas.gaussian_filter1d(array, sigma, axis=-1, order=0, mode='reflect', cval=0., out={np.empty_like(array)})

One-dimensional Gaussian filter.

Parameters :

array : ndarray

input array of a floating-point type

sigma : float

standard deviation for Gaussian kernel (in pixel units)

axis : int, optional

axis to operate on

order : {0, 1, 2, 3}, optional

An order of 0 corresponds to convolution with a Gaussian kernel. An order of 1, 2, or 3 corresponds to convolution with the first, second or third derivatives of a Gaussian. Higher order derivatives are not implemented

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as array as well as be C-contiguous.

Returns :

filtered : ndarray

Filtered version of array

mahotas.get_structuring_elem(A, Bc)

Retrieve appropriate structuring element

Parameters :

A : ndarray

array which will be operated on

Bc : None, int, or array-like

None:

Then Bc is taken to be 1

An integer:
There are two associated semantics:
connectivity

Bc[y,x] = [[ is |y - 1| + |x - 1| <= Bc_i ]]

count

Bc.sum() == Bc_i This is the more traditional meaning (when one writes that “4-connected”, this is what one has in mind).

Fortunately, the value itself allows one to distinguish between the two semantics and, if used correctly, no ambiguity should ever occur.

An array:

This should be of the same nr. of dimensions as A and will be passed through if of the right type. Otherwise, it will be cast.

Returns :

Bc_out : ndarray

Structuring element. This array will be of the same type as A, C-contiguous.

mahotas.haar(f, preserve_energy=True, inline=False)

Haar transform

Parameters :

f : 2-D ndarray

Input image

preserve_energy : bool, optional

Whether to normalise the result so that energy is preserved (the default).

inline : bool, optional

Whether to write the results to the input image. By default, a new image is returned. Integer images are always converted to floating point and copied.

See also

ihaar
function Reverse Haar transform
mahotas.hitmiss(input, Bc, out=np.zeros_like(input))

Hit & Miss transform

For a given pixel position, the hit&miss is True if, when Bc is overlaid on input, centered at that position, the 1 values line up with ``1``s, while the ``0``s line up with ``0``s (``2``s correspond to don’t care).

Parameters :

input : input ndarray

This is interpreted as a binary array.

Bc : ndarray

hit & miss template, values must be one of (0, 1, 2)

out : output array

Returns :

filtered : ndarray

mahotas.idaubechies(f, code, inline=False)

Daubechies wavelet inverse transform

Parameters :

f : ndarray

2-D image

code : str

One of ‘D2’, ‘D4’, ... ‘D20’

inline : bool, optional

Whether to write the results to the input image. By default, a new image is returned. Integer images are always converted to floating point and copied.

See also

haar
function Haar transform (equivalent to D2)
mahotas.ihaar(f, preserve_energy=True, inline=False)

Reverse Haar transform

ihaar(haar(f)) is more or less equal to f (equal, except for possible rounding issues).

Parameters :

f : 2-D ndarray

Input image. If it is an integer image, it is converted to floating point (double).

preserve_energy : bool, optional

Whether to normalise the result so that energy is preserved (the default).

inline : bool, optional

Whether to write the results to the input image. By default, a new image is returned. Integer images are always converted to floating point and copied.

Returns :

f : ndarray

See also

haar
function Forward Haar transform
mahotas.imread(filename, as_grey=False)

Reads an image from file filename

Parameters :

filename : file name

as_grey : Whether to convert to grey scale image (default: no)

Returns :

img : ndarray

mahotas.imresize(img, nsize, order=3)

img’ = imresize(img, nsize)

Resizes img

Parameters :

img : ndarray

nsize : float or tuple(float) or tuple(integers)

Size of return. Meaning depends on the type

float: img’.shape[i] = nsize * img.shape[i] tuple of float: img’.shape[i] = nsize[i] * img.shape[i] tuple of int: img’.shape[i] = nsize[i]

order : integer, optional

Spline order to use (default: 3)

Returns :

img’ : ndarray

See also

scipy.ndimage.zoom
Similar function
scipy.misc.pilutil.imresize
Similar function
mahotas.imsave(*args, **kwargs)

Save an array as in image file.

The output formats available depend on the backend being used.

Arguments:
fname:
A string containing a path to a filename, or a Python file-like object. If format is None and fname is a string, the output format is deduced from the extension of the filename.
arr:
An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.
Keyword arguments:
vmin/vmax: [ None | scalar ]
vmin and vmax set the color scaling for the image by fixing the values that map to the colormap color limits. If either vmin or vmax is None, that limit is determined from the arr min/max value.
cmap:
cmap is a colors.Colormap instance, eg cm.jet. If None, default to the rc image.cmap value.
format:
One of the file extensions supported by the active backend. Most backends support png, pdf, ps, eps and svg.
origin
[ ‘upper’ | ‘lower’ ] Indicates where the [0,0] index of the array is in the upper left or lower left corner of the axes. Defaults to the rc image.origin value.
dpi
The DPI to store in the metadata of the file. This does not affect the resolution of the output image.
mahotas.label(array, Bc={3x3 cross}, output={new array})

Label the array, which is interpreted as a binary array

This is also called connected component labeled, where the connectivity is defined by the structuring element Bc.

See: http://en.wikipedia.org/wiki/Connected-component_labeling

Parameters :

array : ndarray

This will be interpreted as binary array

Bc : ndarray, optional

This is the structuring element to use

out : ndarray, optional

Output array. Must be a C-array, of type np.int32

Returns :

labeled : ndarray

Labeled result

nr_objects : int

Number of objects

mahotas.labeled_sum(array, labeled)

Labeled sum. sum will be an array of size labeled.max() + 1, where sum[i] is equal to np.sum(array[labeled == i]).

Parameters :

array : ndarray of any type

labeled : int ndarray

Label map. This is the same type as returned from mahotas.label()

Returns :

sums : 1-d ndarray of array.dtype

mahotas.majority_filter(img, N=3, out={np.empty(img.shape, np.bool)})

Majority filter

filtered[y,x] is positive if the majority of pixels in the squared of size N centred on (y,x) are positive.

Parameters :

img : ndarray

input img (currently only 2-D images accepted)

N : int, optional

size of filter (must be odd integer), defaults to 3.

out : ndarray, optional

Used for output. Must be Boolean ndarray of same size as img

Returns :

filtered : ndarray

boolean image of same size as img.

mahotas.median_filter(f, Bc={square}, mode='reflect', cval=0.0, out={np.empty(f.shape, f.dtype})

Median filter

Parameters :

f : ndarray

input. Any dimension is supported

Bc : ndarray or int, optional

Defines the neighbourhood, default is a square of side 3.

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as f as well as be C-contiguous.

Returns :

median : ndarray of same type and shape as f

median[i,j] is the median value of the points in f close to (i,j)

mahotas.moments(img, p0, p1, cm=(0, 0), convert_to_float=True)

Returns the p0-p1 moment of image img

The formula computed is

sum_{ij} { img[i,j] (i - c0)**p0 (j - c1)**p1 }

where cm = (c0,c1). If cm is not given, then (0,0) is used.

If image is of an integer type, then it is internally converted to np.float64, unlesss convert_to_float is False. The reason is that, otherwise, overflow is likely except for small images. Since this conversion takes longer than the computation, you can turn it off in case you are sure that your images are small enough for overflow to be an issue. Note that no conversion is made if img is of any floating point type.

Parameters :

img : 2-ndarray

An 2-d ndarray

p0 : float

Power for first dimension

p1 : float

Power for second dimension

cm : (int,int), optional

center of mass (default: 0,0)

convert_to_float : boolean, optional

whether to convert to floating point (default: True)

Returns :

moment: float :

floating point number

mahotas.open(f, Bc={3x3 cross}, out={np.empty_like(f)})

Morphological opening.

open creates the image y by the morphological opening of the image f by the structuring element Bc.

In the binary case, the opening by the structuring element Bc may be interpreted as the union of translations of b included in f. In the gray-scale case, there is a similar interpretation taking the functions umbra.

Parameters :

f : ndarray

Gray-scale (uint8 or uint16) or binary image.

Bc : ndarray, optional

Structuring element (default: 3x3 elementary cross).

out : ndarray, optional

Output array

Returns :

y : ndarray

See also

open
function
mahotas.otsu(img, ignore_zeros=False)

Calculate a threshold according to the Otsu method.

Parameters :

img : an image as a numpy array.

This should be of an unsigned integer type.

ignore_zeros : Boolean

whether to ignore zero-valued pixels (default: False)

Returns :

T : integer

the threshold

mahotas.rank_filter(f, Bc, rank, mode='reflect', cval=0.0, out=None)

Rank filter. The value at ranked[i,j] will be the rank``th largest in the neighbourhood defined by ``Bc.

Parameters :

f : ndarray

input. Any dimension is supported

Bc : ndarray

Defines the neighbourhood. Must be explicitly passed, no default.

rank : integer

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as f as well as be C-contiguous.

Returns :

ranked : ndarray of same type and shape as f

ranked[i,j] is the ``rank``th value of the points in f close to (i,j)

See also

median_filter
A special case of rank_filter
mahotas.rc(img, ignore_zeros=False)

Calculate a threshold according to the Riddler-Calvard method.

Parameters :

img : ndarray

Image of any type

ignore_zeros : boolean, optional

Whether to ignore zero valued pixels (default: False)

Returns :

T : float

threshold

mahotas.regmax(f, Bc={3x3 cross}, out={np.empty(f.shape, bool)})

Regional maxima

Parameters :

f : ndarray

Bc : ndarray, optional

structuring element

out : ndarray, optional

Used for output. Must be Boolean ndarray of same size as f

Returns :

filtered : ndarray

boolean image of same size as f.

See also

locmax
function Local maxima
mahotas.regmin(f, Bc={3x3 cross}, out={np.empty(f.shape, bool)})

Regional minima

Parameters :

f : ndarray

Bc : ndarray, optional

structuring element

out : ndarray, optional

Used for output. Must be Boolean ndarray of same size as f

Returns :

filtered : ndarray

boolean image of same size as f.

See also

locmin
function Local minima
mahotas.sobel(img, just_filter=False)

Compute edges using Sobel’s algorithm

edges is a binary image of edges computed according to Sobel’s algorithm.

This implementation is tuned to match MATLAB’s implementation.

Parameters :

img : Any 2D-ndarray

just_filter : boolean, optional

If true, then return the result of filtering the image with the sobel filters, but do not threashold (default is False).

Returns :

edges : ndarray

Binary image of edges, unless just_filter, in which case it will be an array of floating point values.

mahotas.stretch(img, arg0=None, arg1=None, dtype=<type 'numpy.uint8'>)

img’ = stretch(img, [dtype=np.uint8]) img’ = stretch(img, max, [dtype=np.uint8]) img’ = stretch(img, min, max, [dtype=np.uint8])

Contrast stretch the image to the range [0, max] (first form) or
[min, max] (second form).
Parameters :

img : ndarray

input image. It is not modified by this function

min : integer, optional

minimum value for output [default: 0]

max : integer, optional

maximum value for output [default: 255]

dtype : dtype of output,optional

[default: np.uint8]

Returns :

img’: ndarray :

resulting image. ndarray of same shape as img and type dtype.

mahotas.template_match(f, template, mode='reflect', cval=0., out={np.empty_like(f)})

Match template.

The value at match[i,j] will be the difference (in squared euclidean terms), between template and a same sized window on f centered on that point.

Parameters :

f : ndarray

input. Any dimension is supported

template : ndarray

Template to match. Must be explicitly passed, no default.

mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’, ‘ignore’}

How to handle borders

cval : double, optional

If mode is constant, which constant to use (default: 0.0)

out : ndarray, optional

Output array. Must have same shape and dtype as f as well as be C-contiguous.

Returns :

match : ndarray of same type and shape as f

match[i,j] is the squared euclidean distance between f[i-s0:i+s0,j-s1:j+s1] and template (for appropriately defined s0 and s1).

mahotas.thin(binimg)

Skeletonisation by thinning

Parameters :binimg : Binary input image
Returns :skel : Skeletonised version of binimg
mahotas.wavelet_center(f, border=0, dtype=float, cval=0.0)

fc is a centered version of f with a shape that is composed of powers of 2.

Parameters :

f : ndarray

input image

border : int, optional

The border to use (default is no border)

dtype : type, optional

Type of fc

cval : float, optional

Which value to fill the border with (default is 0)

Returns :

fc : ndarray

See also

wavelet_decenter
function Reverse function
mahotas.wavelet_decenter(w, oshape, border=0)

Undoes the effect of wavelet_center

Parameters :

w : ndarray

Wavelet array

oshape : tuple

Desired shape

border : int, optional

The desired border. This must be the same value as was used for wavelet_center

Returns :

f : ndarray

This will have shape oshape

See also

wavelet_center
function Forward function
mahotas.features.haralick(f, ignore_zeros=False, preserve_haralick_bug=False, compute_14th_feature=False)

Compute Haralick texture features

Computes the Haralick texture features for the four 2-D directions or thirteen 3-D directions (depending on the dimensions of f).

Parameters :

f : ndarray of integer type

input image. 2-D and 3-D images are supported.

ignore_zeros : bool, optional

Whether to ignore zero pixels (default: False).

Returns :

feats : ndarray of np.double

A 4x13 or 4x14 feature vector (one row per direction) if f is 2D, 13x13 or 13x14 if it is 3D. The exact number of features depends on the value of compute_14th_feature

Other Parameters:
 

preserve_haralick_bug : bool, optional

whether to replicate Haralick’s typo (default: False). You probably want to always set this to False unless you want to replicate someone else’s wrong implementation.

compute_14th_feature : bool, optional

whether to compute & return the 14-th feature

Notes

Haralick’s paper has a typo in one of the equations. This function implements the correct feature unless preserve_haralick_bug is True. The only reason why you’d want the buggy behaviour is if you want to match another implementation.

References

Cite the following reference for these features:

@article{Haralick1973,
    author = {Haralick, Robert M. and Dinstein, Its'hak and Shanmugam, K.},
    journal = {Ieee Transactions On Systems Man And Cybernetics},
    number = {6},
    pages = {610--621},
    publisher = {IEEE},
    title = {Textural features for image classification},
    url = {http://ieeexplore.ieee.org/lpdocs/epic03/wrapper.htm?arnumber=4309314},
    volume = {3},
    year = {1973}
}
mahotas.features.lbp(image, radius, points, ignore_zeros=False)

Compute Linear Binary Patterns

The return value is a histogram of feature counts, where position i corresponds to the number of pixels that had code i. The codes are compressed so that impossible codes are not used. Therefore, this is the i``th feature, not just the feature with binary code ``i.

Parameters :

image : ndarray

input image (2-D numpy ndarray)

radius : number (integer or floating point)

radius (in pixels)

points : integer

nr of points to consider

ignore_zeros : boolean, optional

whether to ignore zeros (default: False)

Returns :

features : 1-D numpy ndarray

histogram of features. See above for a caveat on the interpretation of these.

mahotas.features.pftas(img, T={mahotas.threshold.otsu(img)})

Compute parameter free Threshold Adjacency Statistics

TAS were presented by Hamilton et al. in “Fast automated cell phenotype image classification” (http://www.biomedcentral.com/1471-2105/8/110)

The current version is an adapted version which is free of parameters. The thresholding is done by using Otsu’s algorithm (or can be pre-computed and passed in by setting T), the margin around the mean of pixels to be included is the standard deviation. This was first published by Coelho et al. in “Structured Literature Image Finder: Extracting Information from Text and Images in Biomedical Literature” (http://www.springerlink.com/content/60634778710577t0/)

Also returns a version computed on the negative of the binarisation defined by Hamilton et al.

Use tas() to get the original version of the features.

Parameters :

img : ndarray, 2D or 3D

input image

T : integer, optional

Threshold to use (default: compute with otsu)

Returns :

values : ndarray

A 1-D ndarray of feature values

mahotas.features.tas(img)

Compute Threshold Adjacency Statistics

TAS were presented by Hamilton et al. in “Fast automated cell phenotype image classification” (http://www.biomedcentral.com/1471-2105/8/110)

Also returns a version computed on the negative of the binarisation defined by Hamilton et al.

See also pftas() for a variation without any hardcoded parameters.

Parameters :

img : ndarray, 2D or 3D

input image

Returns :

values : ndarray

A 1-D ndarray of feature values

See also

pftas
Parameter free TAS
mahotas.features.zernike(im, degree, radius, cm={center_of_mass(im)})
mahotas.features.zernike_moments(im, radius, degree=8, cm={center_of_mass(im)})

Zernike moments through degree

Returns a vector of absolute Zernike moments through degree for the image im.

Parameters :

im : 2-ndarray

input image

radius : integer

the maximum radius for the Zernike polynomials, in pixels

degree : integer, optional

Maximum degree to use (default: 8)

cm : pair of floats, optional

the centre of mass to use. By default, uses the image’s centre of mass.

Returns :

zvalues : 1-ndarray of floats

Zernike moments

Table Of Contents

Previous topic

History

This Page