Search code examples
opencvcolorsbrightnessandroid

Opencv split and change value in that channel in android


I want to adjust the brightness of frame in opencv camera which is called mRgba. After I split the channel of lab. I hope to adjust the L channel but I don't know how to change the value in the L channel.

   Mat lab_image  = new Mat();
   //mRgba is the frame which shows in the camera
    Imgproc.cvtColor(mRgba, lab_image, Imgproc.COLOR_mRGBA2RGBA);
    Imgproc.cvtColor(lab_image, lab_image, Imgproc.COLOR_RGBA2RGB);
    Imgproc.cvtColor(lab_image, lab_image, Imgproc.COLOR_RGB2Lab);

    // Extract the L channel
    List<Mat> lab_list = new ArrayList(3);
    Core.split(lab_image,lab_list);

    //lab_list.get(0).copyTo(mRgba);

    Mat result_image = new Mat();
    Core.merge(lab_list,result_image);

    Imgproc.cvtColor(result_image, mRgba, Imgproc.COLOR_Lab2RGB);
    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_RGB2RGBA);
    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_RGBA2mRGBA);

I try to use setTo() to set the color but it change the whole color.

lab_list.get(0).setTo(new Scalar(255,255,255,0.1));

I want to add value to increase the whole brightness.I hope the final result can become the following photo. Please give me some help. Thank You.

https://i.sstatic.net/dSr4L.png


Solution

  • Let us say you want to increase your L channel by 50.

    You can do it like this:

    Mat dst = new Mat();
    Core.add(lab_list.get(0), Scalar(50), dst);
    lab_list.set(0, dst);
    

    And then merge the channels like you do already.