Normalization ¶
By: SachaBernheim on April 6, 2024, 7:50 a.m.
The code provided to normalise the images is the following:
def percentile_normalization(image, pmin=2, pmax=99.8, axis=None):
'''
Compute a percentile normalization for the given image.
Parameters:
- image (array): array of the image file.
- pmin (int or float): the minimal percentage for the percentiles to compute.
Values must be between 0 and 100 inclusive.
- pmax (int or float): the maximal percentage for the percentiles to compute.
Values must be between 0 and 100 inclusive.
- axis : Axis or axes along which the percentiles are computed.
The default (=None) is to compute it along a flattened version of the array.
- dtype (dtype): type of the wanted percentiles (uint16 by default)
Returns:
Normalized image (np.ndarray): An array containing the normalized image.
'''
if not (np.isscalar(pmin) and np.isscalar(pmax) and 0 <= pmin < pmax <= 100 ):
raise ValueError("Invalid values for pmin and pmax")
low_p = np.percentile(image, pmin, axis=axis, keepdims=True)
high_p = np.percentile(image, pmax, axis=axis, keepdims=True)
if low_p == high_p:
img_norm = image
print(f"Same min {low_p} and high {high_p}, image may be empty")
else:
img_norm = (image - low_p) / (high_p - low_p)
return img_norm
We are supposed to use it with axis=None
exclusively right? Since we don't want to normalise across rows or columns but across the whole image?