neutompy.metrics.metrics

neutompy.metrics.metrics.CNR(img, croi_signal=[], croi_background=[], froi_signal=[], froi_background=[])[source]

This function computes the Contrast-to-Noise Ratio (CNR) as reported in the equation (2.7) of [1]. The ROI of the signal and the background can be defined using two lists of coordinates or two ImageJ .roi files.

Parameters:
  • img (2d array) – The array representing the image.
  • croi_signal (list) – List that contains the following coordinate of the signal roi: [rowmin, rowmax, colmin, colmax].
  • croi_background (list) – List that contains the following coordinate of the background roi: [rowmin, rowmax, colmin, colmax].
  • froi_signal (string) – Path of the imagej file containing the rectangular ROI of the signal.
  • froi_background (string) – Path of the imagej file containing the rectangular ROI of the background.
Returns:

CNR (float) – The CNR value computed using the ROIs given.

References

[1](1, 2, 3) D. Micieli et al., A comparative analysis of reconstruction methods applied to Neutron Tomography, Journal of Instrumentation, Volume 13, June 2018.
neutompy.metrics.metrics.NRMSE(img, ref, mask='whole')[source]

This function computes the Normalized Root Mean Square Error (see eq. 2.9 in [1]) of an image respect to a reference image.

Parameters:
  • img (2d array) – Test image

  • ref (2d array) – Reference image

  • mask – It represents the type of the ROI where the NRMSE is computed. You can specify: ‘whole’ -> full image

    ‘circ’ -> circular mask ‘custom’ -> custom mask, defined as a boolean matrix of the same shape of the images (img and ref)

  • mask (2d bool array) – Curstom mask of the same shape of the images, where the NRMSE is computed.

Returns:

NRMSE (float) – The NRMSE value computed within the roi specified.

neutompy.metrics.metrics.SSIM(img1, img2, circ_crop=True, L=None, K1=0.01, K2=0.03, sigma=1.5, local_ssim=False)[source]

This function computes the Structural Similarity Index (SSIM) [2]. It returns global SSIM value and, optionally, the local SSIM map.

Parameters:
  • img1 (2d array) – The first image to compare. SSIM index satisfies the condition of simmetry: SSIM(img1, img2) = SSIM(img2, img1)
  • img2 (2d array) – The second image to compare. SSIM index satisfies the condition of simmetry: SSIM(img1, img2) = SSIM(img2, img1)
  • circular_crop (bool, optional) – If True (default) the images are cropped with a circular mask, otherwise the SSIM is computed over the entire image.
  • L (float, optional) – The data range of the input images (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
  • K1 (float, optional) – A constant that prevents the division by zero (see [2]).
  • K2 (float, optional) – A constant that prevents the division by zero (see [2]).
  • sigma (float, optional) – The standard deviation of the Gaussian filter. This parameter sets the minimum scale at which the quality is evaluated.
  • local_ssim (float, optional) – If True, the function returns the local SSIM map.
Returns:

  • ssim (float) – The global SSIM index.
  • map (2d array) – The bidimendional map of the local SSIM index. This is only returned if local_ssim is set to True.

References

[2](1, 2, 3) 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
neutompy.metrics.metrics.FWHM(profile, yerr=None)[source]

This functions computes an edge quality metric from a profile of a sharp edge. The profile is fitted with a generic Gauss sigmoid function. The fitting function was then differentiated and the FWHM of the gaussian obtained is returned by the function. This method is described in detail in [1].

Parameters:
  • profile (1d array) – The line profile of the sharp edge.
  • yerr (1d array, optional) – The vector containing the standard deviation of the edge profile. If not specified the standard deviation of each point is assumed equal to 1.0.
Returns:

  • fwhm (float) – The FWHM mean value.
  • fwhm_err (float) – The FWHM error value
  • profile_fitted (1d array) – The Gauss sigmoid function evaluated for the fitting parameters.
  • popt (list) – List containing the fitting parameters.
  • perr (list) – List containing the errors of the fitting parameters.

neutompy.metrics.metrics.get_line_profile(image, start=(), end=(), froi='', ShowPlot=True, PlotTitle='Profile', linewidth=1, order=1, mode='constant', cval=0.0)[source]

This function returns the intensity profile of an image measured along a line defined by the points:

start = (x_start, y_start) [i.e. (col_start row_start)] end = (x_end, y_en) [i.e. (col_end row_end)]

or an ImageJ .roi file containing the line selection. A plot representing the intensity profile can be shown.

Parameters:
  • image (ndarray) – The image grayscale (2D array) or a stack of images (3d array) with shape (slices, rows, columns). Ffor a 3D array the first axis represents the image index.
  • start (2-tuple of numeric scalar (float or int) (x y) [i.e. (col row)]) – The start point of the scan line.
  • end (2-tuple of numeric scalar (float or int) (x y) [i.e. (col row)]) – The end point of the scan line. The destination point is included in the profile, in constrast to standard numpy indexing.
  • froi (string) – Path of the imagej file containing the line selection.
  • ShowPlot (bool) – If True a canvas is created representing the Plot Profile.
  • linewidth (int, optional) – Width of the scan, perpendicular to the line
  • order (int in {0, 1, 2, 3, 4, 5}, optional) – The order of the spline interpolation to compute image values at non-integer coordinates. 0 means nearest-neighbor interpolation.
  • mode ({‘constant’, ‘nearest’, ‘reflect’, ‘mirror’, ‘wrap’}, optional) – How to compute any values falling outside of the image.
  • cval (float, optional) – If mode is ‘constant’, what constant value to use outside the image.
Returns:

return_value (array) – The intensity profile along the scan line. The length of the profile is the ceil of the computed length of the scan line.

neutompy.metrics.metrics.GMSD(img, ref, rescale=True, map=False)[source]

This function computes the Gradient Magnitude Similarity Deviation (GMSD). This is a Python version of the Matlab script provided by the authors in [3]

Parameters:
  • img (2d array) – Image to compare.
  • ref (2d array) – Reference image.
  • rescale (bool, optional) – If True the input images were rescaled in such a way that ref has a maximum pixel value of 255. If False no rescaling is performed. Default value is True.
  • map (bool, optional) – If True the GMSD and GMS map are returned in a tuple. Default value is False.
Returns:

  • gmsd_val (float) – The GMSD value.
  • gms_map (2d array) – The GMS map, returned only if map is True.

References

[3]Wufeng Xue, Lei Zhang, Xuanqin Mou, and Alan C. Bovik, “Gradient Magnitude Similarity Deviation: A Highly Efficient Perceptual Image Quality Index”, http://www.comp.polyu.edu.hk/~cslzhang/IQA/GMSD/GMSD.htm