linumpy.gpu.image_quality#

GPU-accelerated image quality assessment functions.

This module provides CuPy-accelerated versions of quality assessment functions. All functions automatically fall back to CPU if GPU is not available.

Usage:

from linumpy.gpu.image_quality import (
    compute_ssim_2d_gpu,
    compute_ssim_3d_gpu,
    compute_edge_score_gpu,
    assess_slice_quality_gpu,
)

# All functions accept numpy arrays and return numpy scalars
ssim = compute_ssim_3d_gpu(vol1, vol2)

Attributes#

cp

Functions#

normalize_image_gpu(img)

Normalize image to [0, 1] range on GPU.

compute_ssim_2d_gpu(img1, img2[, win_size])

Compute SSIM between two 2D images using GPU.

compute_ssim_3d_gpu(vol1, vol2[, win_size, sample_depth])

Compute mean SSIM between two 3D volumes using GPU.

compute_edge_score_gpu(vol, reference[, sample_z])

Compute edge preservation score using GPU.

compute_variance_score_gpu(vol, reference)

Compute variance score using GPU.

assess_slice_quality_gpu(vol, vol_before, vol_after[, ...])

Assess overall quality of a slice volume using GPU acceleration.

clear_gpu_memory()

Clear GPU memory pools.

Module Contents#

linumpy.gpu.image_quality.cp = None[source]#
linumpy.gpu.image_quality.normalize_image_gpu(img)[source]#

Normalize image to [0, 1] range on GPU.

Parameters:

img (cp.ndarray) – Input image on GPU.

Returns:

Normalized image.

Return type:

cp.ndarray

linumpy.gpu.image_quality.compute_ssim_2d_gpu(img1, img2, win_size=7)[source]#

Compute SSIM between two 2D images using GPU.

Falls back to CPU if GPU is not available.

Parameters:
  • img1 (np.ndarray) – Input images (2D).

  • img2 (np.ndarray) – Input images (2D).

  • win_size (int) – Window size for SSIM computation.

Returns:

SSIM score (0 to 1, higher is better).

Return type:

float

linumpy.gpu.image_quality.compute_ssim_3d_gpu(vol1, vol2, win_size=7, sample_depth=0)[source]#

Compute mean SSIM between two 3D volumes using GPU.

Parameters:
  • vol1 (np.ndarray) – Input volumes (Z, Y, X).

  • vol2 (np.ndarray) – Input volumes (Z, Y, X).

  • win_size (int) – Window size for SSIM computation.

  • sample_depth (int) – Number of z-planes to sample. 0 = all planes.

Returns:

Mean SSIM score (0 to 1, higher is better).

Return type:

float

linumpy.gpu.image_quality.compute_edge_score_gpu(vol, reference, sample_z=None)[source]#

Compute edge preservation score using GPU.

Parameters:
  • vol (np.ndarray) – Input volume (Z, Y, X) or 2D image.

  • reference (np.ndarray) – Reference volume or image.

  • sample_z (int, optional) – Z-index to sample for 3D volumes.

Returns:

Edge preservation score (0 to 1, higher is better).

Return type:

float

linumpy.gpu.image_quality.compute_variance_score_gpu(vol, reference)[source]#

Compute variance score using GPU.

Parameters:
  • vol (np.ndarray) – Input volume.

  • reference (np.ndarray) – Reference volume.

Returns:

Variance score (0 to 1).

Return type:

float

linumpy.gpu.image_quality.assess_slice_quality_gpu(vol, vol_before, vol_after, sample_depth=5, weights=None)[source]#

Assess overall quality of a slice volume using GPU acceleration.

Parameters:
  • vol (np.ndarray) – The slice volume (Z, Y, X).

  • vol_before (np.ndarray or None) – The previous slice volume.

  • vol_after (np.ndarray or None) – The next slice volume.

  • sample_depth (int) – Number of z-planes to sample for SSIM.

  • weights (dict, optional) – Custom weights for metrics.

Returns:

  • float – Overall quality score (0 to 1).

  • dict – Individual metric values.

Return type:

tuple[float, dict[str, Any]]

linumpy.gpu.image_quality.clear_gpu_memory()[source]#

Clear GPU memory pools.

Return type:

None