我想知道是否可以通过修改其 RGB、HSV(或类似)值来修改图像的对比度。
我目前正在做以下事情来处理亮度、饱和度和色调(在 python 中):
import numpy as np
from PIL import Image as img
import colorsys as cs
#Fix colorsys rgb_to_hsv function
#cs.rgb_to_hsv only works on arrays of shape: [112, 112,255] and non n-dimensional arrays
rgb_to_hsv = np.vectorize(cs.rgb_to_hsv)
hsv_to_rgb = np.vectorize(cs.hsv_to_rgb)
def luminance_edit(a, h, s, new_v):
#Edits V - Luminance
#Changes RGB based on new luminance value
r, g, b = hsv_to_rgb(h, s, new_v)
#Merges R,G,B,A values to form new array
arr = np.dstack((r, g, b, a))
return arr …Run Code Online (Sandbox Code Playgroud)