Input A image is a full RGB image, Output B image is a the same image but with "adjusted" R values
I need to rescale the RGB value to be between 128 and 255, so that minor values than 128 are scaled to an upper value.
RMAX = 127
img = cv2.imread(filename) # load img
blue, green, red = cv2.split(img) # get single color
red = red*RMAX/255+128 # scale the color as I need
but this keep getting a wrong value:
if red value is 255 = 255*127/255+128 should output 255 but return 128
Why this happen?
EDIT:
The color values don't need to be recalculated every time, Would it be better to prepare an array at the start with the range of values, then replace the current value with the one from the array?
ValuesForRed = [0]*255
for i in range(0,255):
ValuesForRed[i]=i*127 / 255 + 128
how to replace the values in the array is now the problem...
should replace the corresponding value with the corresponding index
i.e. red[45]= 0
ValuesForRed[0] = 128
red[45]= 128
started new question at Python Opencv cv2.LUT() how to use
inRange()
function (available for Python OpenCV) to obtain the mask for the image that specifies the pixels, which value is between 129 and 255 (inclusive). See the second answer for more details. – Supersaturated