linumpy.metrics.image_quality#
Image quality assessment functions for slice analysis.
This module provides CPU-based functions for assessing image quality in 3D volumes, including:
Structural Similarity Index (SSIM)
Edge preservation scoring
Variance consistency analysis
Overall slice quality assessment
For GPU-accelerated versions, see linumpy.gpu.image_quality.
Usage:
from linumpy.metrics.image_quality import (
compute_ssim_2d,
compute_ssim_3d,
compute_edge_score,
compute_variance_score,
assess_slice_quality,
)
# Compare two volumes
ssim = compute_ssim_3d(vol1, vol2)
# Assess overall slice quality
quality, metrics = assess_slice_quality(vol, vol_before, vol_after)
Functions#
|
Normalize image to [0, 1] range. |
|
Compute SSIM between two 2D images. |
|
Compute mean SSIM between two 3D volumes. |
|
Compute edge preservation score between volume and reference. |
|
Compute variance consistency score between volume and reference. |
|
Assess overall quality of a slice volume. |
|
Detect calibration slices by their different thickness. |
|
Generate a quality report from slice quality assessments. |
Module Contents#
- linumpy.metrics.image_quality.normalize_image(img)[source]#
Normalize image to [0, 1] range.
- Parameters:
img (np.ndarray) – Input image.
- Returns:
Normalized image as float32.
- Return type:
np.ndarray
- linumpy.metrics.image_quality.compute_ssim_2d(img1, img2, win_size=7)[source]#
Compute SSIM between two 2D images.
- linumpy.metrics.image_quality.compute_ssim_3d(vol1, vol2, win_size=7, sample_depth=0, xy_roi=0)[source]#
Compute mean SSIM between two 3D volumes.
Computes SSIM for each z-slice and returns the mean.
- 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.
xy_roi (int) – Side length of center crop in XY (pixels). 0 = full plane. Use a small value (e.g. 1024) on very large single-resolution zarr arrays to avoid loading gigabytes per plane.
- Returns:
Mean SSIM score (0 to 1, higher is better).
- Return type:
- linumpy.metrics.image_quality.compute_edge_score(vol, reference, sample_z=None)[source]#
Compute edge preservation score between volume and reference.
Uses Sobel edge detection to compare edge structures.
- linumpy.metrics.image_quality.compute_variance_score(vol, reference)[source]#
Compute variance consistency score between volume and reference.
Low variance may indicate data loss or corruption.
- Parameters:
vol (np.ndarray) – Input volume.
reference (np.ndarray) – Reference volume.
- Returns:
Variance score (0 to 1, higher means more similar variance).
- Return type:
- linumpy.metrics.image_quality.assess_slice_quality(vol, vol_before, vol_after, sample_depth=5, weights=None, xy_roi=0)[source]#
Assess overall quality of a slice volume.
Uses multiple metrics to determine slice quality: - SSIM with neighboring slices (50%) - Edge preservation compared to expected structure (30%) - Variance consistency (20%)
- 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. 0 = all.
weights (dict, optional) – Custom weights for metrics. Keys: ‘ssim’, ‘edge’, ‘variance’.
xy_roi (int) – Side length of center crop in XY (pixels). 0 = full plane. Use a small value (e.g. 1024) on very large single-resolution zarr arrays to avoid loading gigabytes per plane.
- Returns:
float – Overall quality score (0 to 1).
dict – Individual metric values.
- Return type:
- linumpy.metrics.image_quality.detect_calibration_slice(volumes, thickness_ratio=1.5)[source]#
Detect calibration slices by their different thickness.
Calibration slices are typically thicker than regular slices.