quantimpy.brisque module¶
Functions for BRISQUE no-reference image quality assesment (NR-IQA)
This module contains various functions for the computation of the BRISQUE 1 no-reference image quality assesment (NR-IQA) for both 2D and 3D NumPy 2 arrays.
- class quantimpy.brisque.asgennorm_gen(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)¶
Bases:
scipy.stats._distn_infrastructure.rv_continuous
Asymmetric generalized normal continuous random variable
This is an asymmetric generalized Gaussian distribution (AGGD) class based on the SciPy 3 scipy.stats.rv_continuous class. The probability density function for asgennorm is 4:
\[f(x, \alpha, \beta) = \frac{\beta}{(1 + a) \Gamma{(\frac{1}{\beta})}} \exp{(-|\frac{x}{a}|^{\beta})}\]where \(a = \alpha\) if \(x < 0\) and \(a = 1\) if \(x \ge 0\), \(\alpha\) is a measure for the standard deviation, \(\Gamma\) is the gamma function (scipy.special.gamma), and \(\beta\) is the shape parameter. For \(\beta = 1\), it is identical to a Laplace distribution and for \(\beta = 2\), it is identical to a normal distribution.
Some of the methods of this class include:
- pdf(x, alpha, beta)¶
Probability distribution function
- cdf(x, alpha, beta)¶
Cumulative distribution function
- fit(data)¶
Fitting the probability distribution function
See also
Examples
This example uses the NumPy 2, and Matplotlib 5 packages.
import numpy as np import matplotlib.pyplot as plt from quantimpy.brisque import asgennorm # Create dataset following the asymmetric generalized Gaussian distribution data = asgennorm.rvs(2,1,size=10000) # Fit the dataset alpha, beta, loc, scale = asgennorm.fit(data) x = np.linspace( asgennorm.ppf(0.001, alpha, beta, loc=loc, scale=scale), asgennorm.ppf(0.999, alpha, beta, loc=loc, scale=scale), 101) # Plot both the dataset and fit plt.plot(x, asgennorm.pdf(x, alpha, beta, loc=loc, scale=scale), 'r-') plt.hist(data, density=True, bins=51) plt.show()
- quantimpy.brisque.coeff(mscn, sample_size, debug)¶
Coefficients of pairwise products of neighboring MSCN coefficients
Compute the fitting coefficients of the MSCN coefficients and the pairwise products of neighboring MSCN coefficients. The MSCN coefficients are fitted with the generalized Gaussian distribution and the pairwise products with the asymetric generalized Gausian distribution. The input 2D or 3D MSCN coefficients can be computed using function
mscn()
. When the debug parameter is set, images of the distributions and their fit are also returned.- Parameters
mscn (ndarray, float) – 2D or 3D MSCN coefficients.
sample_size (int, defaults to 500000) – To reduce computational resources, the distributions can be fitted to a randomly selected subset of the MSCN coefficients. sample_size gives the size of this subset. When -1 is passed, the whole dataset is used. Defaults to 500000.
debug (str, defaults to "None") – Output directory for debugging images. When this parameter is set, images of the distributions and their fit are written to disk. Set to “./” to write to the working directory. The default is “None”.
- Returns
out – 2D or 3D fitting parameters.
- Return type
ndarray, float
See also
Examples
This example uses the NumPy 2, and Matplotlib 5 packages. The NumPy data file “rock_2d.npy” is available on Github 6 7.
import numpy as np import matplotlib.pyplot as plt from quantimpy import brisque as bq # Load data image = np.load("rock_2d.npy") # Compute MSCN coefficients mscn = bq.mscn(image) # Show coefficients plt.gray() plt.imshow(mscn) plt.show()
- quantimpy.brisque.mscn(image, patch, trunc, debug)¶
Mean subtracted contrast normalized (MSCN) coefficients
Compute the mean subtracted contrast normalized (MSCN) coefficients 1 for the 2D or 3D NumPy array image. The MSCN coefficients, \(\hat{I}\), are defined as:
\[\hat{I} = \frac{I - \mu}{\sigma}\]where \(I\) is the original image, \(\mu\) is the local mean field, and \(\sigma\) is the local variance field. The MSCN coefficients serve as input for the function
coeff()
. When the debug parameter is set, images of the local mean field and local variance field are also returned.- Parameters
image (ndarray, {int, uint, float}) – 2D or 3D grayscale input image.
patch (int, defaults to 7) – Size of the patch used to compute the local mean field and local variance field. Defaults to 7.
trunc (float, defaults to 3.0) – Value at which to truncate the normal distribution used to calculate the local mean field and local variance field. Defaults to 3.0.
debug (str, defaults to "None") – Output directory for debugging images. When this parameter is set, images of the local mean field and local variance field are are written to disk. Set to “./” to write to the working directory. The default is “None”.
- Returns
out – The 2D or 3D MSCN coefficients. The return data type is float and the image is normalized betweeen 0 and 1 or -1 and 1.
- Return type
ndarray, float
See also
Examples
This example uses the NumPy package 2. The NumPy data file “rock_2d.npy” is available on Github 6 7.
import numpy as np from quantimpy import brisque as bq # Load data image = np.load("rock_2d.npy") # Compute MSCN coefficients mscn = bq.mscn(image) print(bq.coeff(mscn))
References
- 1(1,2)
Anish Mittal, Anush Moorthy, and Alan Bovik, “No-reference image quality assessment in the spatial domain”, IEEE Transactions on image processing, vol. 21, no. 12, pp 4695-4708, 2012, doi:10.1109/TIP.2012.2214050
- 2(1,2,3,4)
Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt et al., “Array programming with NumPy”, Nature, vol. 585, pp 357-362, 2020, doi:10.1038/s41586-020-2649-2
- 3
Pauli Virtanen, Ralf Gommers, Travis E. Oliphant, et al., “SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python”, Nature Methods, vol. 17, pp 261-272, 2020, doi:10.1038/s41592-019-0686-2
- 4
Nour-Eddine Lasmar, Youssef Stitou, and Yannick Berthoumieu, “Multiscale skewed heavy tailed model for texture analysis”, 16th IEEE International Conference on Image Processing (ICIP), pp 2281-2284, 2009, doi:10.1109/ICIP.2009.5414404
- 5(1,2)
John D. Hunter, “Matplotlib: A 2D Graphics Environment”, Computing in Science & Engineering, vol. 9, no. 3, pp. 90-95, 2007. doi:10.1109/MCSE.2007.55
- 6(1,2)
Catherine Spurin, Tom Bultreys, Maja Rücker, et al., “The development of intermittent multiphase fluid flow pathways through a porous rock”, Advances in Water Resources, vol. 150, 2021, doi:10.1016/j.advwatres.2021.103868
- 7(1,2)
Catherine Spurin, Tom Bultreys, Maja Rücker, et al., “Real-Time Imaging Reveals Distinct Pore-Scale Dynamics During Transient and Equilibrium Subsurface Multiphase Flow”, Water Resources Research, vol. 56, no. 12, 2020, doi:10.1029/2020WR028287