Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV and HLS

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

OpenCV and HLS

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')

OpenCV and HLS

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')

OpenCV and HLS

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