一篇转载(感谢原作者)

Bayer AF是高通最近的平台引入的一个功能,是将AF的fv统计放在Bayer域来做(之前是在YUV域做统计),避免ISP(尤其是降噪模块)影响图像的对比度信息。MSM8996/MSM8952/MSM8976/MSM8956/MSM8953/MSM8937以及之后的平台,都已支持。

The BAF stats engine consists of two parts:

BAF统计引擎包含两个部分:

  • Preprocessing on the image
    (Y-conversion and gamma correction)

对图像进行处理(Y值转换和gamma校正)

  • Focus value generation

聚焦值的生成

The Y-conversion provides the option to
combine RGB bayer pixel quads into one signal, given by specified weight for each channel. The gamma LUT is used to bring
up the contrast in darker pixels in a low light environment.

Y转换提供了将RGBbayer四像素组合为一个信号的方法,该信号由每个通道的指定权重给定。GammaLUT用于提高弱光环境中偏暗像素的对比度。

There are three filter outputs, two for horizontal and one
for vertical. Figure 16-3 shows the submodule in the filters shown in Figure 16-1 (AF_H_1,
AF_V_1, etc)

共有三个滤波器输出:两个用于水平方向,一个用于垂直方向。图16-3给出图16-1中所示滤波器中的子模块(AF_H_1、AF_V_1等)。

A filter block consists of a bit shifter
between an FIR filter cascade and an IIR filter to ensure the input of the IIR is normalized. Following the IIR, the signal goes
through a coring module to remove noise and then the accumulator adds
up the FV.

滤波器块由FIR滤波器级联与IIR滤波器间的位偏移组成,以确保IIR输入标准化。IIR之后,信号通过核化模块去噪,然后累加器对FV进行累加。

There are four submodules in the BAF stats
engine:

BAF统计引擎具有四个子模块:

  • Y-conversion Y转换

  • Gama Lut

  • Scaler定标器

  • Filter滤波器

– FIR

– Shifter位移器

– IIR

– Coring核化

 

 

BAF参数解析

BAF参数大概结构如下:

 

ROI configuration

Using the bounding box defined from the
clip ratio in the legacy structure, the predefined ROI pattern populates the ROI regions from the preset_id, grid_size_h,
and grid_size_v.

使用由传统结构中裁切率定义的边框(即VFE Config中配置的ROI),可以将预定义的ROI模式从preset_id、grid_size_h和grid_size_v填入ROI区域。

If custom ROI is selected in the presert,
the customer is responsible to populate the ROI locations and sizes with regard to camif, without violating the hardware
constraints. Contact QTI for the list of
constraints.

如果当前选择了定制ROI,则由客户在不违反硬件限制条件的情况下填入与camif相关的ROI位置和尺寸。可联系QTI获取限制条件列表。

  • preset_id

ROI模式预设值

  • BAF_ROI_PATTERN_CUSTOM

客户定制ROI

Custom ROI bypasses ROI configuration and directly passes the
structure to the AF port for hardware
configuration.

定制ROI会绕过ROI配置,直接将结构传递至用于硬件配置的AF端口。

  • BAF_ROI_PATTERN_RECT

矩形-传统网格,默认

  • BAF_ROI_PATTERN_CROSS

十字-奇数个网格

  • BAF_ROI_PATTERN_DIAMOND

菱形-奇数个网格

  • BAF_ROI_PATTERN_SPARSE

稀疏型

  • grid_size_h

ROI
grid width ratio with respect to ROI width.

  • grid_size_v

ROI
grid height ratio with respect to ROI height.

This number determines
the number of regions.

每个ROI网格的长宽占整个ROI长宽的比例,默认是0.2.

这个值决定ROI将分成多少个小区域。

  • grid_gap_h

ROI
grid gap width ratio with respect to ROI width.

  • grid_gap_v

ROI
grid gap width ratio with respect to ROI height.

ROI网格间距的配置

注: 当前不支持网格间隔配置

  • num_ROI

  • ROI_custom

客户定制ROI才需要配置

Gamma

  • preset_id

    • AF_TUNING_CUSTOM

客户定制gamma

  • AF_TUNING_PRESET_0

gamma
off

关闭
Gamma

  • AF_TUNING_PRESET_1

gamma
coefficient = 1/2.2

Y =
X^(1/2.2), X ~[0,1]

  • Custom Gamma

定制gamma使能时需要配置

  • ch_sel

Select
to use green channel only or weighted RGB for Y channel.

Processing
channel selection, 0=G, 1=Y.

选择FV统计的通道,写0只对G通道统计,写1统计RGB加权后的Y通道。

  • Y_coeffs

Weight
for R, G, B channel respectively to form Y.

Y
conversion coefficients.

配置Y转换系数,即RGB各通道的权重

  • g_sel

Select for using Gr or Gb channel. Used for Y or G channel path.

Green Channel selection, 0=GR, 1=GB.

绿色通道的选择,默认写0

  • LUT_enable

Use to enable BAF gamma.

使能BAF的gamma

  • gamma_LUT

14bit x 32个参数的gamma表

Filter

  • HV_filter

Filter parameters for high tier BAF.

高档 BAF 的滤波参数。

适用于高通旗舰平台,MSM8996/MSM8998等需要配置这一组参数。

8996有3组滤波器,Horiz 1、Horiz 2、Vertical分别对应参数中的filter 0/1/2。

其中Horiz 1和Horiz 2是由一个13抽头(tap)FIR和一个4阶(order)IIR组成,Vertical没有FIR,只有一个2阶IIR。

  • HV_filter_2nd_tier

Filter parameters for mid tier BAF.

中档 BAF 的滤波参数。

适用于高通中低端平台,MSM8937/MSM8952/MSM8953/MSM8956/MSM8976等需要配置这一组参数。

这些平台只有两组滤波器,Horiz 1、Vertical分别对应参数中的filter 0/1。

其中Horiz 1是由一个13抽头(tap)FIR和一个4阶(order)IIR组成,Vertical没有FIR,只有一个4阶IIR。

  • preset_id

baf_tuning_preset_enum_t
defines the default set for FIR, IIR, and Shifter stored in the AF core. Coring is
not controlled by a
preset.

preset仅用于配置AF core中存储的FIR, IIR, 和 Shifter的默认参数,即filter_custom中的参数。coring不受preset的控制。

  • AF_TUNING_CUSTOM

客户定制滤波器

  • AF_TUNING_PRESET_0

IIR only

  • AF_TUNING_PRESET_1

FIR + IIR

  • AF_TUNING_PRESET_2

FIR only

  • coring

The coring threshold is the maximum FV that enters the coring table.
Any FV larger than this value only has a gain applied. Filter coring tuning
involves adjusting the Coring Index and the Coring Gain.

核化降噪阈值是输入核化降噪表中的最大 FV 值。 任何大于该值的 FV 值都仅应用一个增益。
滤镜核化降噪的调试过程将调整核化降噪指数和核化降噪增益。

  • x_index

17 entries (monotonic), representing level [0 to 16] of coring
suppression

共17个值(单调递增),表示 [0 - 16]的核化抑制等级

Default is x^3 with last
entry = 16

默认最后一个值等于16, 不知道什么意思

Coring suppression level at every 1/16 interval of threshold
value(integer level of up to 16).

核化抑制等级, 以阈值的 1/16 为间隔( 整数等级最高为 16)

0, 0,
0, 0, 0, 0, 1, 1, 2,
3, 4, 5,
7, 9, 11, 13, 16

  • threshold

Defines the sharpness value to be considered Noise

定义被视为噪声的锐度值

Is the minimum sharpness level to skip coring and apply gain

能通过coring并被乘以gain的最小锐度水平

Is the last entry for coring mapping

是coring mapping的最后一项

Minimum focus value per pixel.

每个像素的最小对焦值,与之前FV_min的概念相同。

一般配置在300~450之间。

  • gain

Boost FV output

驱动FV输出

Filter output scaling for sharpness > threshold.

锐化 > 阈值时就乘以这个gain

Range [0, 64]

默认写16,即1倍gain

  • filter_custom

The terms in brackets (for example, [0.11-0.14]) indicate the
normalized frequency passband of each filter. Filters that have higher
passbands, and hence retain higher frequency content, tend to have longer tails
and sharper peaks when compared to filters with passbands in the lower range.

中括号中的数字(例如,[0.11-0.14])表示了每个滤波器标准化后的通带频率。通带频率较高的滤波器,相对有通带频率较低的滤波器,由于保留了比较高的频率分量,FV的曲线更易有长长的尾巴和尖锐的峰值。

 

The options cover several use cases. One such use case is the use of
face detection in conjunction with AF. In this case, because faces tend to have
mainly low-frequency content, the IIR [0.05-0.12] filter is recommended.
However, for scenes containing very small sources of light surrounded by
flatness, the IIR [0.2-0.35] filter has shown better results. The choice of the
filter for a particular application depends on the frequency characteristics of
scenes that are typical of that application.

选项中覆盖了几种使用场景。其中一种场景就是人脸检测和AF结合的情况。这种场景下,因为人脸一般主要包含低频分量,所以推荐使用IIR [0.05-0.12]的滤波器。

然而,对于平坦背景围绕着的点光源的场景(类似海岸城夜景,如下图),IIR
[0.2-0.35]的滤波器表现较好。

 

对于特殊场景下滤波器的选择,要基于这个场景典型的频率特性。

The pixel values at the input to the BAF block are in unsigned
14-bit format. The bit-shift values indicated in the two tables ensure that the
filtered pixel values are converted to unsigned 18-bit data. The increase in
bit width allows the filtered data to have greater precision. The IIR portions
of the filters listed above are designed to have a gain of unity. This means
that when a filter has no FIR component, the bit-shift always has a value of 3.
For filters with non-zero FIR sections, the bitshift varies according to the
gain of the FIR section. When a custom FIR filter is used, it is important that
the bit-shift value be changed according to the gain of the FIR filter to
ensure that the filter output values are expressed in unsigned 18-bit data format.

输入到BAF模块的像素值是14bit无符号数。bit-shift的值确保滤波后的像素值会被转换为18bit无符号数。增加的bit位会使滤波后的数据有更高的精度。上面列出来的IIR部分滤波器的设计有一个单位gain。这意味着若滤波器没有FIR部分,bit-shift的值要设为3。若滤波器使用了非0 FIR,bit-shift会依据FIR的gain变化。当使用了客户定制FIR滤波器,bit-shift的值需要依据FIR滤波器的gain来配置,以确保滤波器输出的值是18bit无符号数。

  • fir_en

Enable/disable FIR filter.

FIR滤波器使能。

FIR(Finite Impulse Response)滤波器:有限长单位冲激响应滤波器,又称为非递归型滤波器,是数字信号处理系统中最基本的元件,它可以在保证任意幅频特性的同时具有严格的线性相频特性,同时其单位抽样响应是有限长的,因而滤波器是稳定的系统。

传递函数:

 基本结构:

 

高通的FIR是13抽头,即n = [0 , 12], 目前高通平台上很少开FIR的滤波器,以后有空再写。

  • fir

  • shift_bits

FIR没开的话这里一般写3。

MSM8952/MSM8976平台且gamma_enabled没有开时写5.

  • iir_en

Enable/disable IIR filter.

IIR滤波器使能。

IIR(Infinite Impulse Response)数字滤波器采用递归型结构,即结构上带有反馈环路。IIR滤波器运算结构通常由延时、乘以系数和相加等基本运算组成,可以组合成直接型、正准型、级联型、并联型四种结构形式,都具有反馈回路。由于运算中的舍入处理,使误差不断累积,有时会产生微弱的寄生振荡。

传递函数:

 

输出公式:

Y(n)={b0x(n)+b1x(n-1)+...+bmx(n-m)}-{a1x(n-1)+a2x(n-2)+...+amx(n-m)}

基本结构:

 

从公式上看,4阶IIR有12个参数,2阶IIR有6个参数,归一化之后a0 = 1,所以4阶IIR只需要10个参数, 2阶IIR只需要5个参数。

高通上4阶IIR使用的是两个2阶IIR级联的方式,如下图,需要10个参数。

 

  • iir

4 order:

b0, b1, b2, a1, a2, b'0, b'1, b'2, a'1, a'2

2 order:

b0, b1, b2, a1, a2

normal light

[0.085, 0.28]

0.178589f, 0.000000f, -0.178589f, 1.723693f, -0.808777f, 0.3125f,
0.000000f, -0.3125f, 1.157227f, -0.609802f

0.227100, 0.000000, -0.2271000, 1.3628000, -0.54570000

高通推荐使用,带通滤波,总体表现较好,平坦场景、饱和像素过多的场景失败率较高。

[0.05-0.35]

0.6633, -1.3266, 0.6633, 1.8638, -0.8870, 1.2275, -2.4551, 1.2275,
1.7259, -0.7474

0.8949, -1.7897, 0.8949, 1.7786, -0.8008

All scene types

文档上推荐,相当于全通滤波,适用所有场景,待测试。

[0.11-0.25]

0.0773,
0, -0.0773, 1.7057, -0.8460, 0.1268, 0, -0.1268, 1.3242, -0.7503

Generic scenes

文档上推荐,带通滤波,待测试。

Lowlight

[0.2-0.35]

0.122559f, 0.000000f, -0.122559f, 1.364258f, -0.754822f, 0.336609f,
0.000000f, -0.336609f, 0.872559f, -0.689087f

0.1936000f, 0.000000f, -0.1936000f, 1.0772000f, -0.61280000f

Scenes with saturated
pixels

高通滤波,对海岸城多光源场景表现很好,但低亮度场景失败率很高。

[0.05-0.12]

0.092346, 0.000000, -0.092346, 1.712158, -0.815308, 0.112976,
0.000000, -0.112976, 1.869690, -0.898743

0.0994000, 0.000000, -0.0994000, 1.7479000, -0.80110000

All scene types except scenes with large number of saturated pixels

高通推荐,低通滤波,低亮度场景表现好,海岸城多光源场景较大概率失败。

[0.05-0.15]

0.6633, -1.3266, 0.6633, 1.8638, -0.8870, 1.2275, -2.4551, 1.2275,
1.7259, -0.7474

文档推荐lowlight和face使用,待测试。

face

[0.05-0.12]

0.092346, 0.000000, -0.092346, 1.712158, -0.815308, 0.112976,
0.000000, -0.112976, 1.869690, -0.898743

0.0994000, 0.000000, -0.0994000, 1.7479000, -0.80110000

高通推荐1,低通滤波,理论上应该用这组

[0.11-0.25]

0.077331543, 0, -0.077331543, 1.705688477, -0.846008301,
0.126831055, 0, -0.126831055, 1.324218750, -0.750305176

这一组参数综合表现最好

[0.2-0.35]

0.122559f, 0.000000f, -0.122559f, 1.364258f, -0.754822f, 0.336609f,
0.000000f, -0.336609f, 0.872559f, -0.689087f

高通推荐2,高通滤波,测试这组参数对人脸表现最稳定,理论行不通,使用时多测试。

HFR

[0.1, 0.2]

0.078064f, 0.000000f, -0.078064f, 1.735413f, -0.843811f, 0.257202f,
0.000000f,-0.257202f, 1.477051f, -0.760071f

0.1208, 0, -0.1208, 1.5911, -0.7584

0.894897f, -1.789673f, 0.894897f, 1.778625f, -0.800781f

HFR模式下表现较好。

其他备用参数

[0.42, 0.57] Spotlight场景适用

0.186900000, 0, -0.186900000, 0.273600000, -0.757900000,
0.186900000, 0, -0.186900000, -0.27370000, -0.757930000

0.1942, 0, -0.1942, 0.0422, -0.6120

0.034790039, 0, -0.034790039, 1.758850098,
-0.930480957, 0.059814453, 0, -0.059814453, 1.817626953, -0.940612793//lowlight表现好,待测试

0.036132813, 0, -0.036132813, 1.842529297, -0.927856445,
0.057556152, 0, -0.057556152, 1.891479492, -0.943298340

0.183800,
-0.366700, 0.183800, 1.781700,
-0.878100, 0.183800, -0.230900,
0.183800, 1.877000, -0.918600

频率范围未知,作为备选方案。

取3组常用的IIR参数 [0.2-0.35] [0.085,0.28][0.05-0.12]分别代表高通、带通、低通滤波器来测试下不同光源下的表现。

1. Normal Light 测试环境:TL84 1000LUX 50CM ISO12233卡

 

从这3张可以明显看出,通带频率越高,合焦附近的峰值越尖锐,但离焦区FV的变化比较小,会影响contrast AF算法对FV变化趋势的判断。

2. LowLight 测试环境:TL84 1000LUX 50CM ISO12233卡

 

LowLight环境下,由于画面中低频信号较多,所以低通滤波这组参数表现最好。而高通滤波仅在合焦区域附近有FV的变化,离焦区域的FV几乎没有变化,若在失焦开始对焦的话,基本会对焦失败。

3. Spotlight 测试环境:全黑环境 30CM 硬纸板戳几个洞放在最大亮度DNP前

 

加一组[0.42, 0.57]的测试, 上面四幅图,只有高通滤波能检测到合焦区的peak,离焦过多的地方也是失效的,而[0.05-0.12][0.085, 0.28]检测不到任何peak点,甚至合焦区域的FV值最低。

SpotLight的AF是比较棘手的问题,PDAF+ [0.2-0.35]finescan能cover大部分spotlight的场景,但会影响LowLight的对焦。高通的Spotlight Detection功能又比较鸡肋,对于星星点点的光源基本上检测不到,遇到这种情况只求评测能放过了。

  • scaler_sel

缩放使能,写0不缩放,写1就以scaler的比例进行缩放再做fv统计。

  • scaler

M N scaler, with M for input size and N for output size. Limited to
integer scale.

Scaler factor for denominator, M/N is the scaler factor, maximum
8/1.

M N缩放器,M是输入尺寸,N是输出尺寸,M/N就是缩放比例,仅支持整数缩放,最大8/1.

  • M

input size

  • N

output size

相关资料

常用二阶IIR滤波系数的计算方法 - eeleader的日志 - 电子工程世界-论坛

反差式对焦评价函数的频率特性考虑 - 知乎专栏

傅里叶分析之掐死教程(完整版)更新于2014.06.06 - 知乎专栏

图解IIR FIR 滤波器在自动对焦中的应用

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值