xdesign.metrics

Objects and methods for computing the quality of reconstructions.

Coverage metrics

Objects and methods for computing coverage based quality metrics.

These methods are based on the scanning trajectory only.

Functions:

coverage_approx(gmin, gsize, ngrid, …[, …]) Approximate procedure coverage with a Riemann sum.
xdesign.metrics.coverage.coverage_approx(gmin, gsize, ngrid, probe_size, theta, h, v, weights=None, anisotropy=1, num_rays=16)[source]

Approximate procedure coverage with a Riemann sum.

The intersection between the beam and each pixel is approximated by using a Reimann sum of n rectangles: width beam.size / n and length dist where dist is the length of segment of the line alpha which passes through the pixel parallel to the beam.

If anisotropy is True, then coverage_map.shape is (M, N, 2, 2), where the two extra dimensions contain coverage anisotopy information as a second order tensor.

Parameters:
  • procedure (Probe generator) – A generator which defines a scanning procedure by returning a sequence of Probe objects.
  • region (np.array [cm]) – A rectangle in which to map the coverage. Specify the bounds as [[min_x, max_x], [min_y, max_y]]. i.e. column vectors pointing to the min and max corner.
  • pixel_size (float [cm]) – The edge length of the pixels in the coverage map in centimeters.
  • n (int) – The number of lines per beam
  • anisotropy (bool) – Whether the coverage map includes anisotropy information
Returns:

coverage_map (numpy.ndarray) – A discretized map of the Probe coverage.

Full-reference metrics

Defines full-referene image quality metricsself.

These methods require a ground truth in order to make a quality assessment.

Functions:

pcc(A, B[, masks]) Return the Pearson product-moment correlation coefficients (PCC).
ssim(img1, img2[, sigma, L, K, scale, …]) Return the Structural SIMilarity index (SSIM) of two images.
msssim(img0, img1[, nlevels, sigma, L, K, …]) Multi-Scale Structural SIMilarity index (MS-SSIM).
xdesign.metrics.fullref.pcc(A, B, masks=None)[source]

Return the Pearson product-moment correlation coefficients (PCC).

Parameters:
  • A, B (ndarray) – The two images to be compared
  • masks (list of ndarrays, optional) – If supplied, the data under each mask is computed separately.
Returns:

covariances (array, list of arrays)

class xdesign.metrics.fullref.ImageQuality(original, reconstruction)[source]

Bases: object

Store information about image quality.

img0
Type:array
img1

Stacks of reference and deformed images.

Type:array
metrics

A dictionary with image quality information organized by scale. metric[scale] = (mean_quality, quality_map)

Type:dict
method

The metric used to calculate the quality

Type:string
quality(method='MSSSIM', L=1.0, **kwargs)[source]

Compute the full-reference image quality of each image pair.

Available methods include SSIM [wang:02], MSSSIM [wang:03], VIFp [Sheikh:15], and FSIM [zhang:11].

Parameters:
  • method (string, optional, (default: MSSSIM)) – The quality metric desired for this comparison. Options include: SSIM, MSSSIM, VIFp, FSIM
  • L (scalar) – The dynamic range of the data. This value is 1 for float representations and 2^bitdepth for integer representations.
xdesign.metrics.fullref.ssim(img1, img2, sigma=1.2, L=1, K=(0.01, 0.03), scale=None, alpha=4, beta_gamma=4)[source]

Return the Structural SIMilarity index (SSIM) of two images.

A modified version of the Structural SIMilarity index (SSIM) based on an implementation by Helder C. R. de Oliveira, based on the implementation by Antoine Vacavant, ISIT lab, antoine.vacavant@iut.u-clermont1.fr http://isit.u-clermont1.fr/~anvacava

xdesign.metrics.fullref.img1
Type:array
xdesign.metrics.fullref.img2

Two images for comparison.

Type:array
xdesign.metrics.fullref.sigma

Sets the standard deviation of the gaussian filter. This setting determines the minimum scale at which quality is assessed.

Type:float
xdesign.metrics.fullref.L

The dynamic range of the data. The difference between the minimum and maximum of the data: 2^bitdepth for integer representations.

Type:scalar
xdesign.metrics.fullref.K

A list of two constants which help prevent division by zero.

Type:2-tuple
xdesign.metrics.fullref.alpha

The exponent which weights the contribution of the luminance term.

Type:float
xdesign.metrics.fullref.beta_gamma

The exponent which weights the contribution of the contrast and structure terms at each level.

Type:list
Returns:metrics (dict) – A dictionary with image quality information organized by scale. metric[scale] = (mean_quality, quality_map) The valid range for SSIM is [-1, 1].

References

Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli. Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13(4):600–612, 2004.

Z. Wang and A. C. Bovik. Mean squared error: Love it or leave it? - A new look at signal fidelity measures. IEEE Signal Processing Magazine, 26(1):98–117, 2009.

Silvestre-Blanes, J., & Pérez-Lloréns, R. (2011, September). SSIM and their dynamic range for image quality assessment. In ELMAR, 2011 Proceedings (pp. 93-96). IEEE.

xdesign.metrics.fullref.msssim(img0, img1, nlevels=5, sigma=1.2, L=1.0, K=(0.01, 0.03), alpha=4, beta_gamma=None)[source]

Multi-Scale Structural SIMilarity index (MS-SSIM).

Parameters:
  • img0 (array)
  • img1 (array) – Two images for comparison.
  • nlevels (int) – The max number of levels to analyze
  • sigma (float) – Sets the standard deviation of the gaussian filter. This setting determines the minimum scale at which quality is assessed.
  • L (scalar) – The dynamic range of the data. This value is 1 for float representations and 2^bitdepth for integer representations.
  • K (2-tuple) – A list of two constants which help prevent division by zero.
  • alpha (float) – The exponent which weights the contribution of the luminance term.
  • beta_gamma (list) – The exponent which weights the contribution of the contrast and structure terms at each level.
Returns:

metrics (dict) – A dictionary with image quality information organized by scale. metric[scale] = (mean_quality, quality_map) The valid range for SSIM is [-1, 1].

References

Multi-scale Structural Similarity Index (MS-SSIM) Z. Wang, E. P. Simoncelli and A. C. Bovik, “Multi-scale structural similarity for image quality assessment,” Invited Paper, IEEE Asilomar Conference on Signals, Systems and Computers, Nov. 2003

Standards-based metrics

Defines standards based image quality metrics.

These methods require the reconstructed image to be of a specifically shaped standard object such as a siemens star or a zone plate.

Functions:

compute_mtf(phantom, image) Approximate the modulation tranfer function using the HyperbolicCocentric phantom.
compute_mtf_ffst(phantom, image[, Ntheta]) Calculate the MTF using the method described in [Friedman:13].
compute_mtf_lwkj(phantom, image) Calculate the MTF using the modulated Siemens Star method in [loebich2007digital].
compute_nps_ffst(phantom, A[, B, plot_type]) Calculate the noise power spectrum from a unit circle image using the method from [Friedman:13].
compute_neq_d(phantom, A, B) Calculate the NEQ according to recommendations by [Dobbins:95].
xdesign.metrics.standards.compute_mtf(phantom, image)[source]

Approximate the modulation tranfer function using the HyperbolicCocentric phantom. Calculate the MTF from the modulation depth at each edge on the line from (0.5,0.5) to (0.5,1). MTF = (hi-lo)/(hi+lo)

Parameters:
  • phantom (HyperbolicConcentric) – Predefined phantom of cocentric rings whose widths decay parabolically.
  • image (ndarray) – The reconstruction of the above phantom.
Returns:

  • wavelength (list) – wavelenth in the scale of the original phantom
  • MTF (list) – MTF values
  • .. deprecated:: 0.3 – This method rapidly becomes inaccurate at small wavelenths because the measurement gets out of phase with the waves due to rounding error. Use another one of the MTF functions instead.
  • .. seealso::compute_mtf_ffst() compute_mtf_lwkj()

xdesign.metrics.standards.compute_mtf_ffst(phantom, image, Ntheta=4)[source]

Calculate the MTF using the method described in [Friedman:13].

Parameters:
  • phantom (UnitCircle) – Predefined phantom with single circle whose radius is less than 0.5.
  • image (ndarray) – The reconstruction of the phantom.
  • Ntheta (scalar) – The number of directions at which to calculate the MTF.
Returns:

  • wavenumber (ndarray) – wavelenth in the scale of the original phantom
  • MTF (ndarray) – MTF values
  • bin_centers (ndarray) – the center of the bins if Ntheta >= 1
  • .. seealso::compute_mtf_lwkj()

xdesign.metrics.standards.compute_mtf_lwkj(phantom, image)[source]

Calculate the MTF using the modulated Siemens Star method in [loebich2007digital].

Parameters:
  • phantom (SiemensStar)
  • image (ndarray) – The reconstruciton of the SiemensStar
Returns:

  • frequency (array) – The spatial frequency in cycles per unit length
  • M (array) – The MTF values for each frequency
  • .. seealso::compute_mtf_ffst()

xdesign.metrics.standards.compute_nps_ffst(phantom, A, B=None, plot_type='frequency')[source]

Calculate the noise power spectrum from a unit circle image using the method from [Friedman:13].

Parameters:
  • phantom (UnitCircle) – The unit circle phantom.
  • A (ndarray) – The reconstruction of the above phantom.
  • B (ndarray) – The reconstruction of the above phantom with different noise. This second reconstruction enables allows use of trend subtraction instead of zero mean normalization.
  • plot_type (string) – ‘histogram’ returns a plot binned by radial coordinate wavenumber ‘frequency’ returns a wavenumber vs wavenumber plot
Returns:

  • bins – Bins for the radially binned NPS
  • counts – NPS values for the radially binned NPS
  • X, Y – Frequencies for the 2D frequency plot NPS
  • NPS (2Darray) – the NPS for the 2D frequency plot

xdesign.metrics.standards.compute_neq_d(phantom, A, B)[source]

Calculate the NEQ according to recommendations by [Dobbins:95].

Parameters:
  • phantom (UnitCircle) – The unit circle class with radius less than 0.5
  • A (ndarray) – The reconstruction of the above phantom.
  • B (ndarray) – The reconstruction of the above phantom with different noise. This second reconstruction enables allows use of trend subtraction instead of zero mean normalization.
Returns:

  • mu_b – The spatial frequencies
  • NEQ – the Noise Equivalent Quanta