[libcamera-devel,v1,0/6] IPA RkISP1 awb and misc improvements
mbox series

Message ID 20211202180410.518232-1-jeanmichel.hautbois@ideasonboard.com
Headers show
Series
  • IPA RkISP1 awb and misc improvements
Related show

Message

Jean-Michel Hautbois Dec. 2, 2021, 6:04 p.m. UTC
Hello,

This series introduces several algorithms or tuning parameters for the
RkISP1 IPA.

First, the imx219 is a non linear CMOS sensor and its channels are
compressed. In order to have a better exposed output frame, we need to
apply a deGamma curve on the raw pixels, which is done by a simple
look-up table on the ISP side. The values are taken from the imx219.json
tuning file in the RPi IPA.

The next algorithm is the black level correction. The output is washed
out if no black correction is applied. Again, use the tuning values from
the imx219 data file in RPi.

Now, we can estimate the AWB gains to apply on the red and blue
channels. The RkISP1 could theoretically give us the red, green and blue
mean values for the current frame, but the kernel seems to lack support
for this. Use the YCrCb estimation instead, and convert the values to
RGB before estimating the gains. We don't have a grid of average values,
only a global mean for each channel.

Next, the color correction matric needs to be a bit modified as the
default one is a simple identity matrix. A very simple estimation uses
the red and blue gains calculated but a real tuning file would be
better, based on color temperature as the imx219 data file.

Last patch introduces the histogram IQ mean estimation as for the IPU3
and uses the maximum of the relative luminance gain and the iqMean gain
to determine the shutter speed and analogue gain to apply.

I wanted to post captured images for each of those algorithm to see the
evolution but I accidentaly broke my sd card connector... and I am now
stuck until I can repair it... :-(

Jean-Michel Hautbois (6):
  ipa: rkisp1: Introduce sensor degamma
  ipa: rkisp1: Use frame index
  ipa: rkisp1: Introduce Black Level Correction
  ipa: rkisp1: Introduce AWB
  ipa: rkisp1: Introduce crosstalk correction
  ipa: rkisp1: agc: Introduce histogram calculation

 src/ipa/rkisp1/algorithms/agc.cpp     |  92 +++++++++++++---
 src/ipa/rkisp1/algorithms/agc.h       |   4 +-
 src/ipa/rkisp1/algorithms/awb.cpp     | 149 ++++++++++++++++++++++++++
 src/ipa/rkisp1/algorithms/awb.h       |  33 ++++++
 src/ipa/rkisp1/algorithms/blc.cpp     |  55 ++++++++++
 src/ipa/rkisp1/algorithms/blc.h       |  30 ++++++
 src/ipa/rkisp1/algorithms/ctk.cpp     |  59 ++++++++++
 src/ipa/rkisp1/algorithms/ctk.h       |  30 ++++++
 src/ipa/rkisp1/algorithms/meson.build |   4 +
 src/ipa/rkisp1/algorithms/sdg.cpp     |  49 +++++++++
 src/ipa/rkisp1/algorithms/sdg.h       |  30 ++++++
 src/ipa/rkisp1/ipa_context.cpp        |  33 ++++++
 src/ipa/rkisp1/ipa_context.h          |  19 ++++
 src/ipa/rkisp1/rkisp1.cpp             |  19 ++--
 14 files changed, 583 insertions(+), 23 deletions(-)
 create mode 100644 src/ipa/rkisp1/algorithms/awb.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/awb.h
 create mode 100644 src/ipa/rkisp1/algorithms/blc.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/blc.h
 create mode 100644 src/ipa/rkisp1/algorithms/ctk.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/ctk.h
 create mode 100644 src/ipa/rkisp1/algorithms/sdg.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/sdg.h

Comments

Peter Griffin Jan. 24, 2022, 4:50 p.m. UTC | #1
Hi Jean-Michel,

On Thu, 02 Dec 2021, Jean-Michel Hautbois wrote:

> Hello,
> 
> This series introduces several algorithms or tuning parameters for the
> RkISP1 IPA.
> 
> First, the imx219 is a non linear CMOS sensor and its channels are
> compressed. In order to have a better exposed output frame, we need to
> apply a deGamma curve on the raw pixels, which is done by a simple
> look-up table on the ISP side. The values are taken from the imx219.json
> tuning file in the RPi IPA.
> 
> The next algorithm is the black level correction. The output is washed
> out if no black correction is applied. Again, use the tuning values from
> the imx219 data file in RPi.
> 
> Now, we can estimate the AWB gains to apply on the red and blue
> channels. The RkISP1 could theoretically give us the red, green and blue
> mean values for the current frame, but the kernel seems to lack support
> for this. Use the YCrCb estimation instead, and convert the values to
> RGB before estimating the gains. We don't have a grid of average values,
> only a global mean for each channel.
> 
> Next, the color correction matric needs to be a bit modified as the
> default one is a simple identity matrix. A very simple estimation uses
> the red and blue gains calculated but a real tuning file would be
> better, based on color temperature as the imx219 data file.
> 
> Last patch introduces the histogram IQ mean estimation as for the IPU3
> and uses the maximum of the relative luminance gain and the iqMean gain
> to determine the shutter speed and analogue gain to apply.
> 
> I wanted to post captured images for each of those algorithm to see the
> evolution but I accidentaly broke my sd card connector... and I am now
> stuck until I can repair it... :-(

I tested this series on my RockPi4b with Sony IMX219, and the image quality looks
much better :)

I didn't take captured images after each algorithm, but I did do some captures
before this series was applied, and after. The captures can be found here:

https://people.linaro.org/~peter.griffin/rkisp1captures/

I have been using ffplay to view them with the following command

ffplay -loglevel warning -v info -f rawvideo -pixel_format nv12 -video_size
"3280x2464" cam0-stream0-000009

FWIW for the series:

Tested-by: Peter Griffin <peter.griffin@linaro.org>

regards,

Peter.
Jean-Michel Hautbois Jan. 24, 2022, 5:09 p.m. UTC | #2
Hi Peter !

On 24/01/2022 17:50, Peter Griffin wrote:
> Hi Jean-Michel,
> 
> On Thu, 02 Dec 2021, Jean-Michel Hautbois wrote:
> 
>> Hello,
>>
>> This series introduces several algorithms or tuning parameters for the
>> RkISP1 IPA.
>>
>> First, the imx219 is a non linear CMOS sensor and its channels are
>> compressed. In order to have a better exposed output frame, we need to
>> apply a deGamma curve on the raw pixels, which is done by a simple
>> look-up table on the ISP side. The values are taken from the imx219.json
>> tuning file in the RPi IPA.
>>
>> The next algorithm is the black level correction. The output is washed
>> out if no black correction is applied. Again, use the tuning values from
>> the imx219 data file in RPi.
>>
>> Now, we can estimate the AWB gains to apply on the red and blue
>> channels. The RkISP1 could theoretically give us the red, green and blue
>> mean values for the current frame, but the kernel seems to lack support
>> for this. Use the YCrCb estimation instead, and convert the values to
>> RGB before estimating the gains. We don't have a grid of average values,
>> only a global mean for each channel.
>>
>> Next, the color correction matric needs to be a bit modified as the
>> default one is a simple identity matrix. A very simple estimation uses
>> the red and blue gains calculated but a real tuning file would be
>> better, based on color temperature as the imx219 data file.
>>
>> Last patch introduces the histogram IQ mean estimation as for the IPU3
>> and uses the maximum of the relative luminance gain and the iqMean gain
>> to determine the shutter speed and analogue gain to apply.
>>
>> I wanted to post captured images for each of those algorithm to see the
>> evolution but I accidentaly broke my sd card connector... and I am now
>> stuck until I can repair it... :-(
> 
> I tested this series on my RockPi4b with Sony IMX219, and the image quality looks
> much better :)
> 
> I didn't take captured images after each algorithm, but I did do some captures
> before this series was applied, and after. The captures can be found here:
> 
> https://people.linaro.org/~peter.griffin/rkisp1captures/
> 
> I have been using ffplay to view them with the following command
> 
> ffplay -loglevel warning -v info -f rawvideo -pixel_format nv12 -video_size
> "3280x2464" cam0-stream0-000009
> 
> FWIW for the series:
> 
> Tested-by: Peter Griffin <peter.griffin@linaro.org>

Thanks for testing !
In order to ease the viewing here are the 9th frame without 3A:
https://pasteboard.co/RVvX1N5XBHeY.png

And with 3A:
https://pasteboard.co/Eav971LRIN3I.png

JM

> 
> regards,
> 
> Peter.