Relative Difference

tomni.illumination_correction.relative_difference(img: numpy.ndarray, gauss_size: int = 301, smooth_size=None, do_normalize: bool = False, resize_ratio=None) numpy.array[source]

Remove large blurry artifacts from an image by calculating the relative difference between the blurred and raw image.

Parameters
  • img (numpy.ndarray) – The input image.

  • gauss_size (int, optional) – The size of the Gaussian filter kernel for artifact removal. Must be an odd number. Defaults to 301.

  • smooth_size (int, optional) – The size of the Gaussian filter kernel applied to the image before division. Must be an odd number. Defaults to None.

  • do_normalize (bool, optional) – If True, the output image is normalized between the minimum and maximum values of the smoothed image. Defaults to False.

  • resize_ratio (float, optional) – Resize ratio for the input image before applying Gaussian blur. Used to increase processing speed. Defaults to None.

Returns

The result image after artifact removal.

Return type

numpy.ndarray

Warning

  • The gauss_size should be an odd number; if it’s even, it will be incremented by 1.

  • This algorithm is not fractal, meaning that applying illumination correction followed by cropping will produce a different result than cropping first.

Note

This function can be used for human vision and as input for algorithms relying on relative pixel differences.