skip to Main Content

i have to correct in Python the color blue level like in Photoshop ( CTRL + L ). I found the code in this topic: Color levels in OpenCV , but this is for RGB and I need it for the Blue only.
Please Help. TKS.

2

Answers


  1. Chosen as BEST ANSWER

    Ok thanks to all. I've solved. This is my code:

        img = cv2.imread("normal.png",1)
        b,g,r = cv2.split(img)
        
        
        inBlack  = np.array([0], dtype=np.float32)
        inWhite  = np.array([255], dtype=np.float32)
        inGamma  = np.array([1.0], dtype=np.float32)
        outBlack = np.array([218], dtype=np.float32)
        outWhite = np.array([255], dtype=np.float32)
    
        b = np.clip( (b - inBlack) / (inWhite - inBlack), 0, 255 )                            
        b = ( b ** (1/inGamma) ) *  (outWhite - outBlack) + outBlack
        b = np.clip( b, 0, 255).astype(np.uint8)
        
        img = cv2.merge((b,g,r))
    

  2. Use split function to seperate the channels

    b,g,r = cv2.split(img)
    

    or slicing

    b = img[:,:,0]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search