darsia.PatchwiseIlluminationCorrection#
- class PatchwiseIlluminationCorrection(baseline_images=None, labels=None, nw=100, eps=1e-06, show_images=True)[source]#
Bases:
BaseCorrectionClass for performing patchwise illumination correction on images.
Initialize the PatchwiseIlluminationCorrection class.
- Parameters:
- baseline_images
list[str] |list[darsia.Image] List of baseline images for correction.
- labels
darsia.Image Label image defining regions for per-label reference color computation within each patch. All unique labels in this image are used for calibration.
- nw
int Number of patches in width direction for patchwise illumination correction. Default is 100.
- eps
float Small constant to avoid division by zero in patchwise illumination correction. Default is 1e-6.
- show_imagesbool
Flag to control whether to display the calibrated image.
- baseline_images
Methods
compute_correction(coefficient_list, ...)Calculate correction coefficients based on baseline images.
correct_array(img)Apply patchwise illumination correction to the input image.
correct_metadata([metadata])Correction routine on metadata level.
extract_color_values_patches(image, labels)Extract RGB values from image patches, averaged per-label within each patch.
load(path)Load correction coefficients from a file.
save(path)Save correction coefficients to a file.
- compute_correction(coefficient_list, coefficient_mean_list)[source]#
Calculate correction coefficients based on baseline images.
- Parameters:
- coefficient_list
list[np.ndarray] List of coefficient matrices for each baseline image.
- coefficient_mean_list
list[np.ndarray] List of mean coefficient values for each baseline image.
- coefficient_list
- Returns:
np.ndarrayArray of correction coefficients.
- correct_array(img)[source]#
Apply patchwise illumination correction to the input image.
- Parameters:
- img
np.ndarray Input image to be corrected.
- img
- Returns:
np.ndarrayCorrected image after applying patchwise illumination correction.
- extract_color_values_patches(image, labels)[source]#
Extract RGB values from image patches, averaged per-label within each patch.
For each patch, computes the mean color per unique label present in that patch, then averages those per-label means (unweighted). This ensures heterogeneous patches (straddling multiple materials) contribute equally per material, regardless of pixel-count distribution.
- Parameters:
- image
np.ndarray Input image (RGB, same shape as labels).
- labels
darsia.Image Label image defining regions for per-label reference color computation within each patch. All unique labels in this image are used for calibration.
- image
- Returns:
TuplecontainingR,G,Bmatrices(shapenhxnw).