top of page
  • 作家相片Johanna

TI ISP系列3 - CFA模块

作者:Lei


1. 什么是CFA?


由CCD或CMOS传感器采集到的图像,其实是一张拜耳阵列2x2格式的单通道灰度图,每个像素点只表示自己所在格的单色分量强度。如果直接把所有的像素点按颜色分配给三通道,很显然会出现一个问题:


以1920x1080的传感器为例,通道分离之后,绿通道图像分辨率下降到原先的1/2,960x540; 而红蓝通道则下降到1/4,480x270。先不说对齐的问题,这种分辨率的图像肯定是没法看的。


为了解决这个问题,CFA(颜色插值矩阵)算法就出现了。简单来说,CFA就是通过插值算法填充像素块中原本空缺的颜色,把每个颜色通道的分辨率还原回传感器尺寸。

现有的图像插值算法大柜包括:


双线性插值、平滑色插值、固定色差插值、边缘敏感插值。


opencv的缩放好像用的就是双线性。双线性虽然处理快,但因为太粗暴也会带来一些边缘伪影、伪彩色的现象,所以在相机ISP里基本用不会。


2. TI TDA4VM ISP的CFA模块


2.1 CFA的节点

搞清楚CFA模块在处于整条ISP的什么位置,我觉得这是理解TI CFA的第一步。

通过之前对DCC Tuning Tool的了解,我们知道每个模块都会在调试完之后保存一份xml文件用于生成bin。


来看生成脚本的一部分:

$DCC_TOOL_PATH/dcc_gen_linux IMX219_rgb2rgb_dcc.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_viss_h3a_aewb_cfg.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_viss_nsf4.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_viss_blc.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_flxd_cfa.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_rawfe_decompand.xml
$DCC_TOOL_PATH/dcc_gen_linux IMX219_viss_h3a_mux_luts_cfg.xml
cat *.bin > ../../dcc_bins/dcc_viss.bin
cp *.bin ../../dcc_bins/linear/
$DCC_TOOL_PATH/dcc_bin2c ../../dcc_bins/dcc_viss.bin $OUT_PATH/dcc_viss_imx219.h dcc_viss_imx219

可以看出CFA模块位于TDA4VM ISP的viss这条线上。


这是TI TDA4VM ISP官方文档中对viss的描述:


虽然图上没画CFA的位置,不过我们在第五条注释中看到了“demosaicing”——去马赛克,这个就是CFA算法了。


2.2 CFA的参数

首先找到DCC tuning tool里CFA的调试面板:



然后来看Ti DCC工具的CFA参数配置界面:



可以看到里面涉及了Gamma、WDR、CFAI几块内容。


2.2.1 CFAI Gamma

关于这个Gamma用法,官方是这么解释的:


CFAI Gamma % (100/G) – CFAI block may apply an inverse gamma. User can specify

the gamma value with an integer value of 100/G. The convention is

CFAI Gamma % => 100/G

Example, to specify a Gamma value of G = 2.0 that corrects the pre-applied gamma of 0.5 in RAWFE for compressing WDR input image to 16-bit, enter here a Gamma % value of 100/2.0 = 50.

Note: If WDR Enable is on, the user entered parameter in the WDR tab, “WDR Gamma

% (100*G)” is the same (as noted by the operations in parentheses) as this parameter.

These values should in almost all cases be equal in order that the color in the final

ISP output images looks correct.


简单来说就是,数据在之前的WDR解压过程中用了一条Gamma,而现在为了让输出的图片看起来更自然,要用一条反gamma去平衡。


配上CFA的输出lut:



Ti的说法乍听上去好像很有道理,不过后来一想,感觉还是不太明白,好端端的CFA为啥非得插个gamma进去?包括AWB、LSC、H3A这些模块都会加条gamma进去,你说你分开来不好吗?


像Inter Movidius的isp,Gamma就是干干净净的单独一个模块摆在CCM后面,看着舒服,理解也方便:


关于gamma的值,按照Ti文档的说法,如果这里的gamma是为矫正WDR而配置的,那么或许在不启用WDR的情况下,应该就把gamma配成100(100/G,G=1),也就是直线。

然而话说gamma=1真的好吗?

正常情况下,原始raw的gamma不都得配个0.5吗?

还是说早在RAWFE模块里,不管开不开WDR解压,都会把gamma=0.5的曲线加上去,所以后面就不用管了???

总之Ti这文档……看着是挺迷惑的,如果有大佬能看明白的话希望给我讲讲。


后面就是CFAI的带宽参数配置了:



2.2.2 关于Green High ,Green Low

还是先看文档解释:

3. CFAI bandwidth: Green High – This is the bandwidth parameter for the 6-tap 1D prototype interpolation filter of green pixels for the non-smooth direction (i.e., the direction bad for interpolation). The corresponding 2D directional interpolation filter is used for interpolating pixels around horizontal or vertical image features. The default value of 0.85 is the highest supported value. Lowering this value will result in less noise, less artifacts, and possibly lower image resolution (i.e., more blurry output image). Increasing this bandwidth made give sharper output images with more noise and artifacts.

4. CFAI bandwidth: Green Low – This is the bandwidth parameter for the 6-tap 1D prototype interpolation filter of green pixels for the smooth direction (i.e., the direction good for interpolation). The default value is 0.38 and the lowest supported value is 0.27. Lowering this value will result in less noise, less artifacts, and possibly lower image resolution (i.e., more blurry output image). Increasing this bandwidth made give sharper output images with more noise and artifacts.

The two prototype 1D filters above are combined together to construct the 2D directional filter for green pixels (Fig. 1-a).


挑几个关键词翻译一下,


6-tap 1D prototype interpolation filter:6抽头1D原型插值滤波器

non-smooth direction:非平滑方向

horizontal or vertical image features:水平或垂直图像特征


然后再来解释一下:

6抽头1D原型插值滤波器:

不懂,反正不是双线插值。


非平滑方向:

两个对应的位置,Green High的解释里是非平滑方向,而Green Low的解释是平滑方向,听起来和平滑色插值很像,但非平滑指的又是什么?想不通,所以这里我更倾向去认为,应该套用边缘敏感插值的理论去解释。

以某个边界点为例,首先我们知道图像的轮廓是有方向,而轮廓通常体现在亮度上,所以Green High代表绿色梯度高的方向,应该保留梯度,应用高带宽的滤波器,而Green Low代表梯度低的方向,其实和平滑区差异不大,所以需要应用低带宽的滤波器尽量去除噪点。


2.2.3 关于Green MidA and MidB

文档解释:

5.CFAI bandwidth: Green MidA and MidB – These are for the bandwidth parameters for the two 6-tap prototype 1D filters used for designing the non-directional interpolation filter for green pixels. These two prototype filters are combined and blended in horizontal and vertical directions to form the 2D R/B non-directional interpolation filter (Fig. 1-b). The non-directional interpolation filter is used for interpolating green pixels around non-directional image features. The default values are 0.78 and 0.38 respectively. Lowering these values will result in less noise, less artifacts, and lower resolution.


既然之前的两项对应轮廓特征的插值,那么从“non-directional interpolation filter is used for interpolating green pixels around non-directional image features”这句话里,我推测MidA and MidB对应的就是平滑区。MidA是水平强度,MidB是垂直强度。


2.2.4 关于R/B Low

文档解释:

6. CFAI bandwidth: R/B Low – This is the bandwidth parameter for the 1D prototype low pass filter for interpolation of Red and Blue pixels. The default value is 0.38 and the lowest supported value is 0.27. The final 2D interpolation filter (Fig. 1-c) is similar to the green non-directional filter but with lower bandwidth. The R/B interpolation also has another part that takes input from green pixels by the using a filter which is the difference of the directional green filter and the R/B non-directional filter (Fig. 1-d).


文档里说的还是很复杂,“这是一个低通滤波器”这句话能直接看懂,又考虑到R/B这种东西,通常是拿来判断色度的,所以我想这个滤波器应该只是单独用来降低R、B平面的采样色噪的。


2.3 CFA的调试

通过上面对文档的分析,我觉得大致可以总结出这样一些调试方法。

gamma:前面开了WDR给个反的gamma值,没开WDR就给100。

WDR enable:这个没什么好说的,就是个开关,和前面保持一致。

Green high : 调高可以让边缘更粗一些,轮廓会更清晰。

Green low : 调低可以让边缘更滑一些,避免斜边出锯齿。

Green MidA and MidB:调低可以让平面更润一点,去亮度噪声效果好。

R/B Low:调低可以去色噪,去花纹。


2.4 附图

最后放上一张图,希望能帮你们理解几种不同的插值滤波器。



104 次查看0 則留言

最新文章

查看全部
bottom of page