EBSD.adaptive_histogram_equalization(kernel_size: Optional[Union[Tuple[int, int], List[int]]] = None, clip_limit: Union[int, float] = 0, nbins: int = 128, show_progressbar: Optional[bool] = None) None[source]#

Enhance the local contrast in an EBSD scan inplace 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.


It is recommended to perform adaptive histogram equalization only after static and dynamic background corrections, 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)