adjust_contrast adjust_contrast ( img, contrast_factor ) [source]

Adjusts contrast of an Image.

  • img (PIL.Image|np.array) – 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 by a factor of 2.


Contrast adjusted image.

Return type

PIL.Image or np.array


import numpy as np
from PIL import Image
from import functional as F

fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')

fake_img = Image.fromarray(fake_img)

converted_img = F.adjust_contrast(fake_img, 0.4)