EBSD.rescale_intensity(relative: bool = False, in_range: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, out_range: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, dtype_out: Optional[Union[str, dtype, type, Tuple[int, int], Tuple[float, float]]] = None, percentiles: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, show_progressbar: Optional[bool] = None) None[source]#

Rescale image intensities inplace.

Output min./max. intensity is determined from out_range or the data type range of the numpy.dtype passed to dtype_out if out_range is None.

This method is based on skimage.exposure.rescale_intensity().


Whether to keep relative intensities between images (default is False). If True, in_range must be None, because in_range is in this case set to the global min./max. intensity.


Min./max. intensity of input images. If not given, in_range is set to pattern min./max intensity. Contrast stretching is performed when in_range is set to a narrower intensity range than the input patterns. Must be None if relative=True or percentiles are passed.


Min./max. intensity of output images. If not given, out_range is set to dtype_out min./max according to skimage.util.dtype.dtype_range.


Data type of rescaled images, default is input images’ data type.


Disregard intensities outside these percentiles. Calculated per image. Must be None if in_range or relative is passed. Default is None.


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


Rescaling RGB images is not possible. Use RGB channel normalization when creating the image instead.


>>> import numpy as np
>>> import kikuchipy as kp
>>> s =

Image intensities are stretched to fill the available grey levels in the input images’ data type range or any data type range passed to dtype_out, either keeping relative intensities between images or not

>>> print(
...     s.inav[0, 0].data.min(), s.inav[0, 0].data.max()
... )
uint8 23 246 26 245
>>> s2 = s.deepcopy()
>>> s.rescale_intensity(dtype_out=np.uint16)
>>> print(
...     s.inav[0, 0].data.min(), s.inav[0, 0].data.max()
... )
uint16 0 65535 0 65535
>>> s2.rescale_intensity(relative=True)
>>> print(
...     s2.inav[0, 0].data.min(), s2.inav[0, 0].data.max()
... )
uint8 0 255 3 253

Contrast stretching can be performed by passing percentiles

>>> s.rescale_intensity(percentiles=(1, 99))

Here, the darkest and brightest pixels within the 1% percentile are set to the ends of the data type range, e.g. 0 and 255 respectively for images of uint8 data type.

Examples using EBSD.rescale_intensity#