Exemple #1
0
def apply_posterize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
    r"""Posterize an image.

    Args:
        input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
        params (Dict[str, torch.Tensor]):
            - params['bits_factor']: uint8 bits number ranged from 0 to 8.

    Returns:
        torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
    """
    bits = params['bits_factor']

    return posterize(input, bits)
Exemple #2
0
def apply_posterize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
    r"""Posterize an image.

    Args:
        input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
        params (Dict[str, torch.Tensor]):
            - params['bits_factor']: uint8 bits number ranged from 0 to 8.

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

    bits = params['bits_factor']

    return posterize(input, bits)
Exemple #3
0
def posterize(x: Tensor, v: float) -> Tensor:
    v = int(v)
    return E.posterize(x, v)
Exemple #4
0
 def apply_transform(self,
                     input: Tensor,
                     params: Dict[str, Tensor],
                     transform: Optional[Tensor] = None) -> Tensor:
     return posterize(input, params["bits_factor"].to(input.device))