我正在尝试为灰度颜色的图像编写对比度调整,但到目前为止找不到正确的方法。这是我想出的:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from scipy import misc
def fix_contrast(image):
minimumColor = np.amin(image)
maximumColor = np.amax(image)
#avg = (minimumColor - maximumColor)/2 first attempt
avg = np.mean(image) #second attempt
colorDownMatrix = image < avg # also tried
colorUpMatrix = image > avg
#also tried: colorUpMatrix = image > avg * 1.2
# and : colorDownMatrix = image < avg* 0.3
image = image - minimumColor*colorDownMatrix
image = image + maximumColor*colorUpMatrix
lessThen0 = …Run Code Online (Sandbox Code Playgroud)