예제 #1
0
def apply_adjust_contrast(input: torch.Tensor,
                          params: Dict[str, torch.Tensor],
                          return_transform: bool = False):
    """Wrapper for adjust_contrast for Torchvision-like param settings.
    Args:
        input (torch.Tensor): Image to be adjusted in the shape of (*, N).
        params['contrast_factor'] (Union[float, torch.Tensor]):
          Contrast adjust factor per element in the batch.
          0 generates a compleatly black image, 1 does not modify
          the input image while any other non-negative number modify the
          brightness by this factor.

    Returns:
        torch.Tensor: Adjusted image.
    """
    input = _transform_input(input)
    _validate_input_dtype(
        input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])

    transformed = adjust_contrast(input,
                                  params['contrast_factor'].to(input.dtype))

    if return_transform:
        identity: torch.Tensor = torch.eye(3,
                                           device=input.device,
                                           dtype=input.dtype).repeat(
                                               input.shape[0], 1, 1)
        return transformed, identity

    return transformed
예제 #2
0
파일: functional.py 프로젝트: rdevon/kornia
def apply_adjust_contrast(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
    """Wrapper for adjust_contrast for Torchvision-like param settings.

    Args:
        input (torch.Tensor): Image to be adjusted in the shape of (*, N).
        params (Dict[str, torch.Tensor]):
            - params['contrast_factor']: Contrast adjust factor per element in the batch.
            0 generates a compleatly black image, 1 does not modify the input image while any other
            non-negative number modify the brightness by this factor.

    Returns:
        torch.Tensor: Adjusted image.
    """
    input = _transform_input(input)
    _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])

    transformed = adjust_contrast(input, params['contrast_factor'].to(input.dtype))

    return transformed