-3

i want to make Lab and YCrCb color palette with trackbar in opencv (python). I got this source code for RGB channel.

https://i.stack.imgur.com/ybVox.png

Would you like to tell me how to change it to Lab channel and YCrCb channel? I'm sorry, i'm just a beginner and i really have no idea about it.

Kimhan
  • 25
  • 6

2 Answers2

0

Instead of changing trackbar values you can change the lab values. After your code add this command and modify for your code. You can use newimg in imshow.

    newimg= cv2.cvtColor(img, cv2.COLOR_Lab2BGR)
onur aslan
  • 283
  • 3
  • 8
  • But my lecturer told me to change the trackbar to other color channel. Do you have suggestion what color channel should i use beside RGB? – Kimhan Oct 24 '17 at 13:22
0

You simply need to change the Color spaces of the image. Just make sure you put the correct ranges for each component. An Example with Lab is below. The a,b have ranges in -127 to 127 and hence am subtracting 127.

import cv2
import numpy as np

def nothing(x):
    pass

img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')

cv2.createTrackbar('L','image',0,100,nothing)
cv2.createTrackbar('A','image',0,255,nothing)
cv2.createTrackbar('B','image',0,255,nothing)

while(1):

    cv2.imshow('image',img)
    k = cv2.waitKey(1) & 0xFF
    if k == 27:
        break

    img= cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
    l = cv2.getTrackbarPos('L','image')
    a = cv2.getTrackbarPos('A','image')-127
    b = cv2.getTrackbarPos('B','image')-127
    img[:] = [l,a,b]





cv2.destroyAllWindows()
I.Newton
  • 1,753
  • 1
  • 10
  • 14