I was wondering if it was possible to modify the contrast of an image, by modifying its RGB, HSV (or similar) values.
I am currently doing the following to mess with luminance, saturation and hue (in 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
I have a separate function to deal with converting to and fro RGB and HSV. A is the alpha channel, h is the hue, s is saturation and new_v is the new V value (luminance).
Is it possible to edit contrast based on these values, or am I missing something?
Edit: I have a separate function that imports images, extracts the RGBA values, and converts them into HSL/HSV. Lets call this function x.
In the code provided (function y), we take the hue(h), saturation(s), luminance (v) and the alpha channel (a) - the HSL values provided from function x, of some image.
The code edits the V value, or the luminance. It does not actually edit the contrast, It's just an example of what I'm aiming to achieve. Using the above data (HSL/HSV/RGB) or similar, I was wondering if it was possible to edit the contrast of an image.
luminance_edit()
function? Your description says you plan to "mess" with luminance and saturation which isn't much help at all. What is the question and what is your incomplete code trying to achieve and what aspect doesn't work? – Mark Setchell