Image feature extraction and manipulation (medpy.features)

This package contains various functions for feature extraction and manipulation in medical images.

Intensity medpy.features.intensity

Functions to extracts intensity based features. Ready to be manipulated with medpy.features.utilities and used in scikit-learn.

intensities(image[, mask]) Takes a simple or multi-spectral image and returns its voxel-wise intensities.
centerdistance(image[, voxelspacing, mask]) Takes a simple or multi-spectral image and returns its voxel-wise center distance in mm.
centerdistance_xdminus1(image, dim[, …]) Implementation of centerdistance that allows to compute sub-volume wise centerdistances.
indices(image[, voxelspacing, mask]) Takes an image and returns the voxels ndim-indices as voxel-wise feature.
shifted_mean_gauss(image[, offset, sigma, …]) The approximate mean over a small region at an offset from each voxel.
mask_distance(image[, voxelspacing, mask]) Computes the distance of each point under the mask to the mask border taking the voxel-spacing into account.
local_mean_gauss(image[, sigma, …]) Takes a simple or multi-spectral image and returns the approximate mean over a small region around each voxel.
gaussian_gradient_magnitude(image[, sigma, …]) Computes the gradient magnitude (edge-detection) of the supplied image using gaussian derivates and returns the intensity values.
median(image[, size, voxelspacing, mask]) Computes the multi-dimensional median filter and returns the resulting values per voxel.
local_histogram(image[, bins, rang, …]) Computes multi-dimensional histograms over a region around each voxel.
hemispheric_difference(image[, …]) Computes the hemispheric intensity difference between the brain hemispheres of an brain image.

Feature representation

Features can be one or more dimensional and are kept in the following structures:

===== | == == =====
s1    | s2 s3 [...]
f1.1  | 
f1.2  | 
f2.1  | 
f3.1  | 
f3.2  | 
[...] | 
===== | == == =====

, where each column sX denotes a single sample (voxel) and each row a features element e.g. f1 is constitutes a 2-dimensional features and occupies therefore two rows, while f2 is a single element features with a single row. Entries of this array are of type float. These feature representation forms are processable by the scikit-learn methods.

Multi-spectral images

This package was originally designed for MR images and is therefore suited to handle multi-spectral data such as RGB and MR images. Each feature extraction function can be supplied with list/tuple of images instead of an image. in which case they are considered co-registered and the feature is extracted from all of them independently.

Utilities medpy.feature.utilities

A number of utilities to manipulate feature vectors created with medpy.features.intensity.

normalize(vector[, cutoffp, model]) Returns a feature-wise normalized version of the supplied vector.
normalize_with_model(vector, model) Normalize as with normalize, but not based on the data of the passed feature vector, but rather on a learned model created with normalize.
append(*vectors) Takes an arbitrary number of vectors containing features and append them (horizontally).
join(*vectors) Takes an arbitrary number of aligned vectors of the same length and combines them into a single vector (vertically).

Histogram medy.features.histogram

Functions to create various kinds of fuzzy histograms with the fuzzy_histogram function.

fuzzy_histogram(a[, bins, range, normed, …]) Compute a fuzzy histogram.
triangular_membership(bin_center, bin_width) Create a triangular membership function for a fuzzy histogram bin.
trapezoid_membership(bin_center, bin_width, …) Create a trapezium membership function for a fuzzy histogram bin.
gaussian_membership(bin_center, bin_width, …) Create a gaussian membership function for a fuzzy histogram bin.
sigmoidal_difference_membership(bin_center, …) Create the difference of two sigmoids as membership function for a fuzzy histogram bin.

Available membership functions

function (string to pass to membership argument of fuzzy_histogram)

  • triangular_membership (triangular)
  • trapezoid_membership (trapezoid)
  • gaussian_membership (gaussian)
  • sigmoidal_difference_membership (sigmoid)

The smoothness term

The smoothness term determines the affected neighbourhood, e.g., when set to 2, all values in the range (2 * bin_width + 1/2 bin_wdith) to the left and right of this bin (center) contribute to this bin. Therefore it determines the smoothing factor of this fuzzy membership function. More clearly the smoothness term determines how much the function reaches into the adjunct bins.

An example of the smoothness parameter:

              ____________ ________ ____________ ________ ____________
             /          / \        / \       /  \        / \          \ 
            /          /   \      /   \     /    \      /   \          \ 
           /          /     \    /     \   /      \    /     \          \ 
        x-3        x-2        x-1        x          x+1        x+2        x+3
              |-nbh      |          |crisp bin |          |      +nbh|

The considered value v is associated with the bin x using crisp (i.e. standard) histograms. For fuzzy histograms with a smoothness of 2, its membership value for the bins x-smoothness (x-2) until x+smoothness (x+2) is computed. While it also might have a membership values for bins further away from x, these are considered to be only marginal and are therefore nor computed. This leads to a speed-up that is especially important when a great number of fuzzy histograms have to be computed.

Boundary effect / the guarantee parameter

Values near the left and right border of the histogram might not contribute with a full value of 1 to the histogram, as part of their contribution lies outside of the histogram range. To avoid this affect (which can be quite strong for histograms with few bins and a height smoothness term), set ‘guarantee’ to True. The histogram size is then selected to be (left_side - smoothness * bin_width till right_side + smoothness * bin_width) and therefore neglect all boundary effects.

Plots of the membership functions can e.g. be found at .