RandomColorGrayScale#

class RandomColorGrayScale(p)[source]#

Bases: object

Randomly convert per-point RGB color to grayscale.

With probability p, replaces data_dict["color"] with its luminance (ITU-R 0.2989 R + 0.587 G + 0.114 B) broadcast back to 3 channels. Requires "color" with at least 3 channels. Registered as RandomColorGrayScale — use this string as the type in a transform=[...] 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
static rgb_to_grayscale(color, num_output_channels=1)[source]#