Module: metrics

skimage.metrics.adapted_rand_error([…])

Compute Adapted Rand error as defined by the SNEMI3D contest.

skimage.metrics.contingency_table(im_true, …)

Return the contingency table for all regions in matched segmentations.

skimage.metrics.mean_squared_error(image0, …)

Compute the mean-squared error between two images.

skimage.metrics.normalized_root_mse(…[, …])

Compute the normalized root mean-squared error (NRMSE) between two images.

skimage.metrics.peak_signal_noise_ratio(…)

Compute the peak signal to noise ratio (PSNR) for an image.

skimage.metrics.structural_similarity(im1, …)

Compute the mean structural similarity index between two images.

skimage.metrics.variation_of_information([…])

Return symmetric conditional entropies associated with the VI.

adapted_rand_error

skimage.metrics.adapted_rand_error(image_true=None, image_test=None, *, table=None, ignore_labels=(0, ))[source]

Compute Adapted Rand error as defined by the SNEMI3D contest. [R406]

Parameters

image_true : ndarray of int

Ground-truth label image, same shape as im_test.

image_test : ndarray of int

Test image.

table : scipy.sparse array in crs format, optional

A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed on the fly.

ignore_labels : sequence of int, optional

Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.

Returns

are : float

The adapted Rand error; equal to \(1 - \frac{2pr}{p + r}\), where p and r are the precision and recall described below.

prec : float

The adapted Rand precision: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the test image.

rec : float

The adapted Rand recall: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the true image.

Notes

Pixels with label 0 in the true segmentation are ignored in the score.

References

R406(1,2)

Arganda-Carreras I, Turaga SC, Berger DR, et al. (2015) Crowdsourcing the creation of image segmentation algorithms for connectomics. Front. Neuroanat. 9:142. DOI:10.3389/fnana.2015.00142

Examples using skimage.metrics.adapted_rand_error

contingency_table

skimage.metrics.contingency_table(im_true, im_test, *, ignore_labels=(), normalize=False)[source]

Return the contingency table for all regions in matched segmentations.

Parameters

im_true : ndarray of int

Ground-truth label image, same shape as im_test.

im_test : ndarray of int

Test image.

ignore_labels : sequence of int, optional

Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.

normalize : bool

Determines if the contingency table is normalized by pixel count.

Returns

cont : scipy.sparse.csr_matrix

A contingency table. cont[i, j] will equal the number of voxels labeled i in im_true and j in im_test.

mean_squared_error

skimage.metrics.mean_squared_error(image0, image1)[source]

Compute the mean-squared error between two images.

Parameters

image0, image1 : ndarray

Images. Any dimensionality, must have same shape.

Returns

mse : float

The mean-squared error (MSE) metric.

Notes

Changed in version 0.16: This function was renamed from skimage.measure.compare_mse to skimage.metrics.mean_squared_error.

Examples using skimage.metrics.mean_squared_error

normalized_root_mse

skimage.metrics.normalized_root_mse(image_true, image_test, *, normalization='euclidean')[source]

Compute the normalized root mean-squared error (NRMSE) between two images.

Parameters

image_true : ndarray

Ground-truth image, same shape as im_test.

image_test : ndarray

Test image.

normalization : {‘euclidean’, ‘min-max’, ‘mean’}, optional

Controls the normalization method to use in the denominator of the NRMSE. There is no standard method of normalization across the literature [R407]. The methods available here are as follows:

  • ‘euclidean’ : normalize by the averaged Euclidean norm of im_true:

    NRMSE = RMSE * sqrt(N) / || im_true ||
    

    where || . || denotes the Frobenius norm and N = im_true.size. This result is equivalent to:

    NRMSE = || im_true - im_test || / || im_true ||.
    
  • ‘min-max’ : normalize by the intensity range of im_true.

  • ‘mean’ : normalize by the mean of im_true

Returns

nrmse : float

The NRMSE metric.

Notes

Changed in version 0.16: This function was renamed from skimage.measure.compare_nrmse to skimage.metrics.normalized_root_mse.

References

R407(1,2)

https://en.wikipedia.org/wiki/Root-mean-square_deviation

peak_signal_noise_ratio

skimage.metrics.peak_signal_noise_ratio(image_true, image_test, *, data_range=None)[source]

Compute the peak signal to noise ratio (PSNR) for an image.

Parameters

image_true : ndarray

Ground-truth image, same shape as im_test.

image_test : ndarray

Test image.

data_range : int, optional

The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.

Returns

psnr : float

The PSNR metric.

Notes

Changed in version 0.16: This function was renamed from skimage.measure.compare_psnr to skimage.metrics.peak_signal_noise_ratio.

References

R408

https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

structural_similarity

skimage.metrics.structural_similarity(im1, im2, *, win_size=None, gradient=False, data_range=None, multichannel=False, gaussian_weights=False, full=False, **kwargs)[source]

Compute the mean structural similarity index between two images.

Parameters

im1, im2 : ndarray

Images. Any dimensionality with same shape.

win_size : int or None, optional

The side-length of the sliding window used in comparison. Must be an odd value. If gaussian_weights is True, this is ignored and the window size will depend on sigma.

gradient : bool, optional

If True, also return the gradient with respect to im2.

data_range : float, optional

The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.

multichannel : bool, optional

If True, treat the last dimension of the array as channels. Similarity calculations are done independently for each channel then averaged.

gaussian_weights : bool, optional

If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.

full : bool, optional

If True, also return the full structural similarity image.

Returns

mssim : float

The mean structural similarity index over the image.

grad : ndarray

The gradient of the structural similarity between im1 and im2 [R410]. This is only returned if gradient is set to True.

S : ndarray

The full SSIM image. This is only returned if full is set to True.

Other Parameters

use_sample_covariance : bool

If True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window.

K1 : float

Algorithm parameter, K1 (small constant, see [R409]).

K2 : float

Algorithm parameter, K2 (small constant, see [R409]).

sigma : float

Standard deviation for the Gaussian when gaussian_weights is True.

Notes

To match the implementation of Wang et. al. [R409], set gaussian_weights to True, sigma to 1.5, and use_sample_covariance to False.

Changed in version 0.16: This function was renamed from skimage.measure.compare_ssim to skimage.metrics.structural_similarity.

References

R409(1,2,3,4)

Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1109/TIP.2003.819861

R410(1,2)

Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. arXiv:0901.0065 DOI:10.1007/s10043-009-0119-z

Examples using skimage.metrics.structural_similarity

variation_of_information

skimage.metrics.variation_of_information(image0=None, image1=None, *, table=None, ignore_labels=())[source]

Return symmetric conditional entropies associated with the VI. [R411]

The variation of information is defined as VI(X,Y) = H(X|Y) + H(Y|X). If X is the ground-truth segmentation, then H(X|Y) can be interpreted as the amount of under-segmentation and H(X|Y) as the amount of over-segmentation. In other words, a perfect over-segmentation will have H(X|Y)=0 and a perfect under-segmentation will have H(Y|X)=0.

Parameters

image0, image1 : ndarray of int

Label images / segmentations, must have same shape.

table : scipy.sparse array in csr format, optional

A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed with skimage.evaluate.contingency_table. If given, the entropies will be computed from this table and any images will be ignored.

ignore_labels : sequence of int, optional

Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.

Returns

vi : ndarray of float, shape (2,)

The conditional entropies of image1|image0 and image0|image1.

References

R411(1,2)

Marina Meilă (2007), Comparing clusterings—an information based distance, Journal of Multivariate Analysis, Volume 98, Issue 5, Pages 873-895, ISSN 0047-259X, DOI:10.1016/j.jmva.2006.11.013.

Examples using skimage.metrics.variation_of_information