Skip to content

module api.transforms.image.photometric


function Normalize

Normalize(img, mean, std, to_rgb=True)

Normalize the image and convert BGR2RGB.

Args:

  • img (np.ndarray): original image.

  • mean (sequence): Mean values of 3 channels.

  • std (sequence): Std values of 3 channels.

  • to_rgb (bool): Whether to convert the image from BGR to RGB, default is true.

Returns:

  • dict: {'img': Normalized results, 'img_norm_cfg': {'mean': ..., 'std': ..., 'to_rgb':...}}

function ToTensor

ToTensor(img: ndarray)

Args:

  • img (np.ndarray): (1) transpose (HWC->CHW), (2)to tensor

Returns:

a torch.Tensor


function PhotoMetricDistortion

PhotoMetricDistortion(
    img,
    brightness_delta=32,
    contrast_range=(0.5, 1.5),
    saturation_range=(0.5, 1.5),
    hue_delta=18
)

Apply photometric distortion to image sequentially, every dictprocessation is applied with a probability of 0.5. The position of random contrast is in second or second to last.

  1. random brightness

  2. random contrast (mode 0)

  3. convert color from BGR to HSV

  4. random saturation

  5. random hue

  6. convert color from HSV to BGR

  7. random contrast (mode 1)

Args:

  • img (np.ndarray): imput image.

  • brightness_delta (int): delta of brightness.

  • contrast_range (tuple): range of contrast.

  • saturation_range (tuple): range of saturation.

  • hue_delta (int): delta of hue.

Returns:

  • dict: distorted_image