3

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.stack.imgur.com/dSr4L.png

ng2b30
  • 351
  • 6
  • 18

1 Answers1

1

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.

Sunreef
  • 4,452
  • 21
  • 33
  • Thank you very much. I try it first. I want to ask one more question. Can we apply something like gamma correction (http://www.pyimagesearch.com/2015/10/05/opencv-gamma-correction/) in opencv for android? I think the main point I don't know how to apply the following function in android. Can anyone give me some suggestions? table = np.array([((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]).astype("uint8") cv2.LUT(image, table) – ng2b30 Aug 17 '16 at 13:57
  • Yes, you can do it. The [LUT function](http://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#LUT) is available for Android too. Just try to translate the python code in the tutorial to Java. – Sunreef Aug 17 '16 at 14:00
  • how about the np? Where do this come from? – ng2b30 Aug 17 '16 at 14:02
  • np refers to a Python library called NumPy that allows for efficient array manipulation. You should have equivalent functions in OpenCV on Android or you could do it by hand. – Sunreef Aug 17 '16 at 14:03
  • Thank a lot and one more question XD. Does the color space representation have differences between c++ and java? like the hsv , the maximum s and v value are 255 in java. How about in c++? also 255? – ng2b30 Aug 17 '16 at 14:15
  • OpenCV in Java is mostly a wrapper around C++ functions. This means that there are few differences between the Java and C++ API of OpenCV. To answer your specific question: yes, the values for s and v go from 0 to 255 for 8-bit images in C++ too. – Sunreef Aug 17 '16 at 14:23
  • I have some problems about the performance of the result of increasing the L channel. The opencv camera become slower than before. How can i adjust the code so that it will become smooth? – ng2b30 Aug 18 '16 at 05:32