MCPcopy Create free account
hub / github.com/NVIDIA/semantic-segmentation / adjust_contrast

Function adjust_contrast

transforms/transforms.py:212–229  ·  view source on GitHub ↗

Adjust contrast of an Image. Args: img (PIL Image): PIL Image to be adjusted. contrast_factor (float): How much to adjust the contrast. Can be any non negative number. 0 gives a solid gray image, 1 gives the original image while 2 increases the contrast b

(img, contrast_factor)

Source from the content-addressed store, hash-verified

210
211
212def adjust_contrast(img, contrast_factor):
213 """Adjust contrast of an Image.
214
215 Args:
216 img (PIL Image): PIL Image to be adjusted.
217 contrast_factor (float): How much to adjust the contrast. Can be any
218 non negative number. 0 gives a solid gray image, 1 gives the
219 original image while 2 increases the contrast by a factor of 2.
220
221 Returns:
222 PIL Image: Contrast adjusted image.
223 """
224 if not _is_pil_image(img):
225 raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
226
227 enhancer = ImageEnhance.Contrast(img)
228 img = enhancer.enhance(contrast_factor)
229 return img
230
231
232def adjust_saturation(img, saturation_factor):

Callers 1

get_paramsMethod · 0.85

Calls 1

_is_pil_imageFunction · 0.85

Tested by

no test coverage detected