RandomColorGrayScale#
- class RandomColorGrayScale(p)[source]#
Bases:
objectRandomly convert per-point RGB color to grayscale.
With probability
p, replacesdata_dict["color"]with its luminance (ITU-R0.2989 R + 0.587 G + 0.114 B) broadcast back to 3 channels. Requires"color"with at least 3 channels. Registered asRandomColorGrayScale— use this string as thetypein atransform=[...]config list.- Parameters:
p (float) – Probability of applying the grayscale conversion.
Example
>>> import numpy as np >>> data = {"color": np.array([[255., 0., 0.]], dtype="f4")} >>> RandomColorGrayScale(p=1.0)(data)["color"].round(2) array([[76.22, 76.22, 76.22]], dtype=float32) # 0.2989*R luminance, 3 channels