OpenCV and HLS

asked 2013-12-08 04:39:47 -0600

SmokedCheese gravatar image

updated 2013-12-08 05:17:52 -0600

Why when i'm open first image, then convert to HLS, extract hue and set saturation and lightness to 127, then convert to RGB and save (second image). Why colors is wrong? image description image description

import cv2, numpy
img = cv2.imread('image.png')
img = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)
hue = img.T[0]
sl = numpy.repeat(numpy.uint8(127), hue.shape[0] * hue.shape[1])
sl  = sl.reshape(hue.shape)
img = numpy.array((hue, sl, sl)).T
img = cv2.cvtColor(img, cv2.COLOR_HLS2RGB)
Image.fromarray(img).save('pew.png')

But when i do

img = cv2.cvtColor(img, cv2.COLOR_HLS2BGR)

all is right
image description

edit retag flag offensive close merge delete