VirtualBSEImage.adaptive_histogram_equalization(kernel_size: Tuple[int, int] | List[int] | None = None, clip_limit: int | float = 0, nbins: int = 128, show_progressbar: bool | None = None, inplace: bool = True, lazy_output: bool | None = None) None | VirtualBSEImage | LazyVirtualBSEImage[source]#

Enhance the local contrast using adaptive histogram equalization.

This method uses skimage.exposure.equalize_adapthist().


Shape of contextual regions for adaptive histogram equalization, default is 1/4 of image height and 1/4 of image width.


Clipping limit, normalized between 0 and 1 (higher values give more contrast). Default is 0.


Number of gray bins for histogram (“data range”), default is 128.


Whether to show a progressbar. If not given, the value of hyperspy.api.preferences.General.show_progressbar is used.


Whether to operate on the current signal or return a new one. Default is True.


Whether the returned signal is lazy. If not given this follows from the current signal. Can only be True if inplace=False.


Equalized signal, returned if inplace=False. Whether it is lazy is determined from lazy_output.


It is recommended to perform adaptive histogram equalization only after static and dynamic background corrections of EBSD patterns, otherwise some unwanted darkening towards the edges might occur.

The default window size might not fit all pattern sizes, so it may be necessary to search for the optimal window size.


Load one pattern from the small nickel dataset, remove the background and perform adaptive histogram equalization. A copy without equalization is kept for comparison.

>>> import kikuchipy as kp
>>> s =[0, 0]
>>> s.remove_static_background()
>>> s.remove_dynamic_background()
>>> s2 = s.deepcopy()
>>> s2.adaptive_histogram_equalization()

Compute the intensity histograms and plot the patterns and histograms

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> hist, _ = np.histogram(, range=(0, 255))
>>> hist2, _ = np.histogram(, range=(0, 255))
>>> _, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
>>> _ = ax0.imshow(
>>> _ = ax1.imshow(
>>> _ = ax2.plot(hist)
>>> _ = ax3.plot(hist2)