rescale_intensity#
- VirtualBSEImage.rescale_intensity(relative: bool = False, in_range: Union[None, Tuple[int, int], Tuple[float, float]] = None, out_range: Union[None, Tuple[int, int], Tuple[float, float]] = None, dtype_out: Optional[Union[str, dtype, type, Tuple[int, int], Tuple[float, float]]] = None, percentiles: Union[None, Tuple[int, int], Tuple[float, float]] = None, show_progressbar: Optional[bool] = None, inplace: bool = True, lazy_output: Optional[bool] = None) Union[None, VirtualBSEImage, LazyVirtualBSEImage][source]#
Rescale image intensities.
Output min./max. intensity is determined from
out_rangeor the data type range of thenumpy.dtypepassed todtype_outifout_rangeisNone.This method is based on
skimage.exposure.rescale_intensity().- Parameters:
- relative
Whether to keep relative intensities between images (default is
False). IfTrue,in_rangemust beNone, becausein_rangeis in this case set to the global min./max. intensity. Use with care, as this requires the computation of the min./max. intensity of the signal before rescaling.- in_range
Min./max. intensity of input images. If not given,
in_rangeis set to pattern min./max intensity. Contrast stretching is performed whenin_rangeis set to a narrower intensity range than the input patterns. Must beNoneifrelative=Trueorpercentilesare passed.- out_range
Min./max. intensity of output images. If not given,
out_rangeis set todtype_outmin./max according toskimage.util.dtype.dtype_range.- dtype_out
Data type of rescaled images, default is input images’ data type.
- percentiles
Disregard intensities outside these percentiles. Calculated per image. Must be
Noneifin_rangeorrelativeis passed. Default isNone.- show_progressbar
Whether to show a progressbar. If not given, the value of
hyperspy.api.preferences.General.show_progressbaris used.- inplace
Whether to operate on the current signal or return a new one. Default is
True.- lazy_output
Whether the returned signal is lazy. If not given this follows from the current signal. Can only be
Trueifinplace=False.
- Returns:
s_outRescaled signal, returned if
inplace=False. Whether it is lazy is determined fromlazy_output.
See also
Notes
Rescaling RGB images is not possible. Use RGB channel normalization when creating the image instead.
Examples
>>> import numpy as np >>> import kikuchipy as kp >>> s = kp.data.nickel_ebsd_small()
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.data.dtype, s.data.min(), s.data.max(), ... 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.data.dtype, s.data.min(), s.data.max(), ... s.inav[0, 0].data.min(), s.inav[0, 0].data.max() ... ) uint16 0 65535 0 65535 >>> s2.rescale_intensity(relative=True) >>> print( ... s2.data.dtype, s2.data.min(), s2.data.max(), ... 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
uint8data type.