pyiqa.archs.brisque_arch

BRISQUE Metric

Created by: https://github.com/photosynthesis-team/piq/blob/master/piq/brisque.py

Modified by: Jiadi Mo (https://github.com/JiadiMo)

Reference:

MATLAB codes: https://live.ece.utexas.edu/research/Quality/index_algorithms.htm BRISQUE; Pretrained model from: https://github.com/photosynthesis-team/piq/releases/download/v0.4.0/brisque_svm_weights.pt

Module Contents

pyiqa.archs.brisque_arch.default_model_urls[source]
pyiqa.archs.brisque_arch.brisque(x: torch.Tensor, kernel_size: int = 7, kernel_sigma: float = 7 / 6, test_y_channel: bool = True, sv_coef: torch.Tensor = None, sv: torch.Tensor = None, gamma: float = 0.05, rho: float = -153.591, scale: float = 1, version: str = 'original') torch.Tensor[source]

Interface of BRISQUE index.

Parameters:
  • x (torch.Tensor) – An input tensor. Shape \((N, C, H, W)\).

  • kernel_size (int) – The side-length of the sliding window used in comparison. Must be an odd value.

  • kernel_sigma (float) – Sigma of normal distribution.

  • test_y_channel (bool) – Whether to use the y-channel of YCBCR.

  • sv_coef (torch.Tensor) – Support vector coefficients.

  • sv (torch.Tensor) – Support vectors.

  • gamma (float) – Gamma parameter for the RBF kernel.

  • rho (float) – Bias term in the decision function.

  • scale (float) – Scaling factor for the features.

  • version (str) – Version of the BRISQUE implementation (‘original’ or ‘matlab’).

Returns:

Value of BRISQUE index.

Return type:

torch.Tensor

References

Mittal, Anish, Anush Krishna Moorthy, and Alan Conrad Bovik. “No-reference image quality assessment in the spatial domain.” IEEE Transactions on image processing 21, no. 12 (2012): 4695-4708.

pyiqa.archs.brisque_arch.natural_scene_statistics(luma: torch.Tensor, kernel_size: int = 7, sigma: float = 7.0 / 6) torch.Tensor[source]

Compute natural scene statistics (NSS) features for a given luminance image.

Parameters:
  • luma (torch.Tensor) – Luminance image tensor.

  • kernel_size (int) – Size of the Gaussian kernel.

  • sigma (float) – Standard deviation of the Gaussian kernel.

Returns:

NSS features.

Return type:

torch.Tensor

pyiqa.archs.brisque_arch.scale_features(features: torch.Tensor) torch.Tensor[source]

Scale features to the range [-1, 1] based on predefined feature ranges.

Parameters:

features (torch.Tensor) – Input features.

Returns:

Scaled features.

Return type:

torch.Tensor

pyiqa.archs.brisque_arch.rbf_kernel(features: torch.Tensor, sv: torch.Tensor, gamma: float = 0.05) torch.Tensor[source]

Compute the Radial Basis Function (RBF) kernel between features and support vectors.

Parameters:
  • features (torch.Tensor) – Input features.

  • sv (torch.Tensor) – Support vectors.

  • gamma (float) – Gamma parameter for the RBF kernel.

Returns:

RBF kernel values.

Return type:

torch.Tensor

class pyiqa.archs.brisque_arch.BRISQUE(kernel_size: int = 7, kernel_sigma: float = 7 / 6, test_y_channel: bool = True, version: str = 'original', pretrained_model_path: str = None)[source]

Bases: torch.nn.Module

Creates a criterion that measures the BRISQUE score.

Parameters:
  • kernel_size (int) – By default, the mean and covariance of a pixel is obtained by convolution with given filter_size. Must be an odd value.

  • kernel_sigma (float) – Standard deviation for Gaussian kernel.

  • test_y_channel (bool) – Whether to use the y-channel of YCBCR.

  • version (str) – Version of the BRISQUE implementation (‘original’ or ‘matlab’).

  • pretrained_model_path (str, optional) – The model path.

kernel_size[source]

The side-length of the sliding window used in comparison.

Type:

int

kernel_sigma[source]

Sigma of normal distribution.

Type:

float

test_y_channel[source]

Whether to use the y-channel of YCBCR.

Type:

bool

sv_coef

Support vector coefficients.

Type:

torch.Tensor

sv[source]

Support vectors.

Type:

torch.Tensor

gamma

Gamma parameter for the RBF kernel.

Type:

float

rho

Bias term in the decision function.

Type:

float

scale

Scaling factor for the features.

Type:

float

version[source]

Version of the BRISQUE implementation (‘original’ or ‘matlab’).

Type:

str

forward(x: torch.Tensor) torch.Tensor[source]

Computation of BRISQUE score as a loss function.

Parameters:

x (torch.Tensor) – An input tensor with (N, C, H, W) shape. RGB channel order for colour images.

Returns:

Value of BRISQUE metric.

Return type:

torch.Tensor