Shortcuts

RandomGrayscale

class mmpretrain.datasets.transforms.RandomGrayscale(prob=0.1, keep_channels=False, channel_weights=(1.0, 1.0, 1.0), color_format='bgr')[source]

Randomly convert image to grayscale with a probability.

Required Key:

  • img

Modified Key:

  • img

Added Keys:

  • grayscale

  • grayscale_weights

Parameters:
  • prob (float) – Probability that image should be converted to grayscale. Defaults to 0.1.

  • keep_channels (bool) – Whether keep channel number the same as input. Defaults to False.

  • channel_weights (tuple) – The grayscale weights of each channel, and the weights will be normalized. For example, (1, 2, 1) will be normalized as (0.25, 0.5, 0.25). Defaults to (1., 1., 1.).

  • color_format (str) – Color format set to be any of ‘bgr’, ‘rgb’, ‘hsv’. Note: ‘hsv’ image will be transformed into ‘bgr’ format no matter whether it is grayscaled. Defaults to ‘bgr’.

transform(results)[source]

Apply random grayscale on results.

Parameters:

results (dict) – Result dict contains the data to transform.

Returns:

Results with grayscale image.

Return type:

dict

Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.