viqa.nr_metrics.snr.SNR¶
- class viqa.nr_metrics.snr.SNR(data_range=255, normalize=False, **kwargs)[source]¶
Class to calculate the signal-to-noise ratio (SNR) for an image.
- score_val¶
SNR score value of the last calculation.
- Type:
float
- parameters¶
Dictionary containing the parameters for SNR calculation.
- Type:
dict
- Parameters:
data_range ({1, 255, 65535}, default=255) – Data range of the returned data in data loading. Is used for image loading when
normalize
is True. Passed toviqa.utils.load_data()
.normalize (bool, default False) – If True, the input images are normalized to the
data_range
argument.**kwargs (optional) – Additional parameters for data loading. The keyword arguments are passed to
viqa.utils.load_data()
.chromatic (bool, default False) –
If True, the input images are expected to be RGB images.
Note
Currently not supported.
- score(img, **kwargs)[source]¶
Calculate the signal-to-noise ratio (SNR) for an image.
- Parameters:
img (np.ndarray or Tensor or str or os.PathLike) – Image to calculate score of.
**kwargs (optional) – Additional parameters for SNR calculation. The keyword arguments are passed to
viqa.nr_metrics.snr.signal_to_noise_ratio()
. Ifsignal_center
andradius
are not given the class attributeparameters
is used.
- Returns:
score_val – SNR score value.
- Return type:
float
- print_score(decimals=2)[source]¶
Print the SNR score value of the last calculation.
- Parameters:
decimals (int, default=2) – Number of decimal places to print the score value.
- Warns:
RuntimeWarning – If
score_val
is not available.
- visualize_centers(img, signal_center=None, radius=None, export_path=None, **kwargs)[source]¶
Visualize the centers for SNR calculation.
The visualization shows the signal region in a matplotlib plot. If export_path is provided, the plot is saved to the path.
- Parameters:
img (np.ndarray or Tensor or str or os.PathLike) – Image to visualize.
signal_center (Tuple(int), optional) – Center of the signal. Order is
(x, y)
for 2D images and(x, y, z)
for 3D images. If not given the class attributeparameters
is used.radius (int, optional) – Width of the regions. If not given the class attribute
parameters
is used.export_path (str or os.PathLike, optional) – Path to export the visualization to.
**kwargs (optional) – Additional parameters for visualization. The keyword arguments are passed to
matplotlib.pyplot.subplots()
.
- Raises:
ImportError – If the visualization fails in a non-interactive environment.
ValueError – If the given signal_center is not in the same dimension as the image. If the center is too close to the border. If the image is not 2D or 3D.
TypeError – If the center is not a tuple of integers. If the radius is not a positive integer.
- set_centers(img, **kwargs)[source]¶
Visualize and set the centers for SNR calculation interactively.
The visualization shows the signal region in a matplotlib plot.
- Parameters:
img (np.ndarray or Tensor or str or os.PathLike) – Image to visualize.
**kwargs (optional) –
Additional parameters for visualization. The keyword arguments are passed to
visualize_centers()
andmatplotlib.pyplot.subplots()
.signal_center
, andradius
can be provided as starting points for the interactive center selection. If not provided, the center of the image is used as the starting point.Caution
The class attribute
parameters
takes precedence over the given parameters.
Warning
This method is only available in an IPython environment. If not in an IPython environment, the method will try to visualize the centers in a non-interactive environment.
- Raises:
ImportError – If the visualization fails in a non-interactive environment.
ValueError – If the given signal_center is not in the same dimension as the image. If the center is too close to the border. If the image is not 2D or 3D.
TypeError – If the center is not a tuple of integers. If the radius is not a positive integer.
- export_results(path, filename)¶
Export the score to a csv file.
- Parameters:
path (str) – The path where the csv file should be saved.
filename (str) – The name of the csv file.
Notes
The arguments get passed to
viqa.utils.export_results()
.
- load_images(img)¶
Load the image.
Uses the
viqa.utils.load_data()
function to load the image.- Parameters:
img (np.ndarray, viqa.ImageArray, torch.Tensor, str or os.PathLike) – The image to load.
- Returns:
img – The loaded image as an
viqa.utils.ImageArray
.- Return type:
viqa.ImageArray