Unverified Commit 7fd24918 authored by Tongzhou Wang's avatar Tongzhou Wang Committed by GitHub
Browse files

F_t add factor nonnegativity checks for adjust_* (#2356)

* F_t add factor nonnegativity checks for adjust_*

* Update functional_tensor.py

* Update functional_tensor.py

* Update functional_tensor.py

* Update functional_tensor.py
parent 6fe11d5c
...@@ -92,6 +92,9 @@ def adjust_brightness(img: Tensor, brightness_factor: float) -> Tensor: ...@@ -92,6 +92,9 @@ def adjust_brightness(img: Tensor, brightness_factor: float) -> Tensor:
Returns: Returns:
Tensor: Brightness adjusted image. Tensor: Brightness adjusted image.
""" """
if brightness_factor < 0:
raise ValueError('brightness_factor ({}) is not non-negative.'.format(brightness_factor))
if not _is_tensor_a_torch_image(img): if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.') raise TypeError('tensor is not a torch image.')
...@@ -110,6 +113,9 @@ def adjust_contrast(img: Tensor, contrast_factor: float) -> Tensor: ...@@ -110,6 +113,9 @@ def adjust_contrast(img: Tensor, contrast_factor: float) -> Tensor:
Returns: Returns:
Tensor: Contrast adjusted image. Tensor: Contrast adjusted image.
""" """
if contrast_factor < 0:
raise ValueError('contrast_factor ({}) is not non-negative.'.format(contrast_factor))
if not _is_tensor_a_torch_image(img): if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.') raise TypeError('tensor is not a torch image.')
...@@ -143,7 +149,7 @@ def adjust_hue(img, hue_factor): ...@@ -143,7 +149,7 @@ def adjust_hue(img, hue_factor):
Returns: Returns:
Tensor: Hue adjusted image. Tensor: Hue adjusted image.
""" """
if not(-0.5 <= hue_factor <= 0.5): if not (-0.5 <= hue_factor <= 0.5):
raise ValueError('hue_factor ({}) is not in [-0.5, 0.5].'.format(hue_factor)) raise ValueError('hue_factor ({}) is not in [-0.5, 0.5].'.format(hue_factor))
if not _is_tensor_a_torch_image(img): if not _is_tensor_a_torch_image(img):
...@@ -171,13 +177,16 @@ def adjust_saturation(img: Tensor, saturation_factor: float) -> Tensor: ...@@ -171,13 +177,16 @@ def adjust_saturation(img: Tensor, saturation_factor: float) -> Tensor:
Args: Args:
img (Tensor): Image to be adjusted. img (Tensor): Image to be adjusted.
saturation_factor (float): How much to adjust the saturation. 0 will saturation_factor (float): How much to adjust the saturation. Can be any
give a black and white image, 1 will give the original image while non negative number. 0 gives a black and white image, 1 gives the
2 will enhance the saturation by a factor of 2. original image while 2 enhances the saturation by a factor of 2.
Returns: Returns:
Tensor: Saturation adjusted image. Tensor: Saturation adjusted image.
""" """
if saturation_factor < 0:
raise ValueError('saturation_factor ({}) is not non-negative.'.format(saturation_factor))
if not _is_tensor_a_torch_image(img): if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.') raise TypeError('tensor is not a torch image.')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment