skimage.metrics
Metrics corresponding to images, e.g., distance metrics, similarity, etc.
Compute Adapted Rand error as defined by the SNEMI3D contest. | |
Return the contingency table for all regions in matched segmentations. |
Metrics corresponding to images, e.g., distance metrics, similarity, etc.
Compute Adapted Rand error as defined by the SNEMI3D contest. | |
Return the contingency table for all regions in matched segmentations. |
Calculate the Hausdorff distance between nonzero elements of given images. |
Returns pair of points that are Hausdorff distance apart between nonzero elements of given images. |
Compute the mean-squared error between two images. |
Compute the normalized mutual information (NMI). |
Compute the normalized root mean-squared error (NRMSE) between two images. |
Compute the peak signal to noise ratio (PSNR) for an image. |
Compute the mean structural similarity index between two images. |
Return symmetric conditional entropies associated with the VI. |
Compute Adapted Rand error as defined by the SNEMI3D contest. [1]
Ground-truth label image, same shape as im_test.
Test image.
A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed on the fly.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
Relative weight given to precision and recall in the adapted Rand error calculation.
The adapted Rand error.
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.
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.
Pixels with label 0 in the true segmentation are ignored in the score.
The adapted Rand error is calculated as follows:
, where is the probability that a pixel has the same label in the test image in the true image, is the probability that a pixel has label in the true image, and is the probability that a pixel has label in the test image.
Default behavior is to weight precision and recall equally in the adapted Rand error calculation. When alpha = 0, adapted Rand error = recall. When alpha = 1, adapted Rand error = precision.
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
Return the contingency table for all regions in matched segmentations.
Ground-truth label image, same shape as im_test.
Test image.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
Determines if the contingency table is normalized by pixel count.
The return type of cont, either scipy.sparse.csr_array or
scipy.sparse.csr_matrix (default).
A contingency table. cont[i, j] will equal the number of voxels
labeled i in im_true and j in im_test. Depending on sparse_type,
this can be returned as a scipy.sparse.csr_array.
Calculate the Hausdorff distance between nonzero elements of given images.
Arrays where True represents a point that is included in a
set of points. Both arrays must have the same shape.
The method to use for calculating the Hausdorff distance.
standard is the standard Hausdorff distance, while modified
is the modified Hausdorff distance.
The Hausdorff distance between coordinates of nonzero pixels in
image0 and image1, using the Euclidean distance.
The Hausdorff distance [1] is the maximum distance between any point on
image0 and its nearest point on image1, and vice-versa.
The Modified Hausdorff Distance (MHD) has been shown to perform better
than the directed Hausdorff Distance (HD) in the following work by
Dubuisson et al. [2]. The function calculates forward and backward
mean distances and returns the largest of the two.
M. P. Dubuisson and A. K. Jain. A Modified Hausdorff distance for object matching. In ICPR94, pages A:566-568, Jerusalem, Israel, 1994. DOI:10.1109/ICPR.1994.576361 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1.8155
>>> points_a = (3, 0)
>>> points_b = (6, 0)
>>> shape = (7, 1)
>>> image_a = np.zeros(shape, dtype=bool)
Returns pair of points that are Hausdorff distance apart between nonzero elements of given images.
The Hausdorff distance [1] is the maximum distance between any point on
image0 and its nearest point on image1, and vice-versa.
Arrays where True represents a point that is included in a
set of points. Both arrays must have the same shape.
A pair of points that have Hausdorff distance between them.
>>> points_a = (3, 0)
>>> points_b = (6, 0)
>>> shape = (7, 1)
>>> image_a = np.zeros(shape, dtype=bool)
Compute the mean-squared error between two images.
Images. Any dimensionality, must have same shape.
The mean-squared error (MSE) metric.
Full tutorial on calibrating Denoisers Using J-Invariance
Compute the normalized mutual information (NMI).
The normalized mutual information of and is given by:
where is the entropy, is the set of image values, and is the probability of occurrence of value .
It was proposed to be useful in registering images by Colin Studholme and colleagues [1]. It ranges from 1 (perfectly uncorrelated image values) to 2 (perfectly correlated image values, whether positively or negatively).
Images to be compared. The two input images must have the same number of dimensions.
The number of bins along each axis of the joint histogram.
The normalized mutual information between the two arrays, computed at
the granularity given by bins. Higher NMI implies more similar
input images.
If the images don’t have the same number of dimensions.
If the two input images are not the same shape, the smaller image is padded with zeros.
C. Studholme, D.L.G. Hill, & D.J. Hawkes (1999). An overlap invariant entropy measure of 3D medical image alignment. Pattern Recognition 32(1):71-86 DOI:10.1016/S0031-3203(98)00091-0
Compute the normalized root mean-squared error (NRMSE) between two images.
Ground-truth image, same shape as im_test.
Test image.
Controls the normalization method to use in the denominator of the NRMSE. There is no standard method of normalization across the literature [1]. 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 =
The NRMSE metric.
Compute the peak signal to noise ratio (PSNR) for an image.
Ground-truth image, same shape as im_test.
Test image.
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
The PSNR metric.
Full tutorial on calibrating Denoisers Using J-Invariance
Compute the mean structural similarity index between two images.
Please pay attention to the data_range parameter with floating-point images.
Images. Any dimensionality with same shape.
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.
If True, also return the gradient with respect to im2.
The data range of the input image (difference between maximum and minimum possible values). By default, this is estimated from the image data type. This estimate may be wrong for floating-point image data. Therefore it is recommended to always pass this scalar value explicitly (see note below).
If data_range is not specified, the range is automatically guessed
based on the image data type. However for floating-point image data, this
estimate yields a result double the value of the desired range, as the
dtype_range in skimage.util.dtype.py has defined intervals from -1 to
+1. This yields an estimate of 2, instead of 1, which is most often
required when working with image data (as negative light intensities are
nonsensical). In case of working with YCbCr-like color data, note that
these ranges are different per channel (Cb and Cr have double the range
of Y), so one cannot calculate a channel-averaged SSIM with a single call
to this function, as identical ranges are assumed for each channel.
To match the implementation of Wang et al. [1], set gaussian_weights
to True, sigma to 1.5, use_sample_covariance to False, and
specify the data_range argument.
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
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
Return symmetric conditional entropies associated with the VI. [1]
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(Y|X) 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.
Label images / segmentations, must have same shape.
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.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
The conditional entropies of image1|image0 and image0|image1.
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.
‘min-max’ : normalize by the intensity range of im_true.
‘mean’ : normalize by the mean of im_true
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
If True, also return the full structural similarity image.
The mean structural similarity index over the image.
The gradient of the structural similarity between im1 and im2 [2].
This is only returned if gradient is set to True.
The full SSIM image. This is only returned if full is set to True.
If True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window.
Algorithm parameter, K1 (small constant, see [1]).
Algorithm parameter, K2 (small constant, see [1]).
Standard deviation for the Gaussian when gaussian_weights is True.