Bayer AF Tuning Guide

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 tocombine RGB bayer pixel quads into one signal, given by specified weight for each channel. The gamma LUT is used to bringup the contrast in darker pixels in a low light environment.

Y轉換提供了將RGBbayer四像素組合為一個信號的方法,該信號由每個通道的指定權重給定。GammaLUT用於提高弱光環境中偏暗像素的對比度。

There are three filter outputs, two for horizontal and onefor 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 shifterbetween an FIR filter cascade and an IIR filter to ensure the input of the IIR is normalized. Following the IIR, the signal goesthrough a coring module to remove noise and then the accumulator addsup the FV.

濾波器塊由FIR濾波器級聯與IIR濾波器間的位偏移組成,以確保IIR輸入標準化。IIR之後,信號通過核化模塊去噪,然後累加器對FV進行累加。

There are four submodules in the BAF statsengine:

BAF統計引擎具有四個子模塊:

  • Y-conversion Y轉換
  • Gama Lut
  • Scaler定標器
  • Filter濾波器

– FIR

– Shifter位移器

– IIR

– Coring核化

BAF參數解析

BAF參數大概結構如下:

ROI configuration

Using the bounding box defined from theclip 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 hardwareconstraints. Contact QTI for the list ofconstraints.

如果當前選擇了定製ROI,則由客戶在不違反硬體限制條件的情況下填入與camif相關的ROI位置和尺寸。可聯繫QTI獲取限制條件列表。

  • preset_id

ROI模式預設值

  • BAF_ROI_PATTERN_CUSTOM

客戶定製ROI

Custom ROI bypasses ROI configuration and directly passes thestructure to the AF port for hardwareconfiguration.

定製ROI會繞過ROI配置,直接將結構傳遞至用於硬體配置的AF埠。

  • BAF_ROI_PATTERN_RECT

矩形-傳統網格,默認

  • BAF_ROI_PATTERN_CROSS

十字-奇數個網格

  • BAF_ROI_PATTERN_DIAMOND

菱形-奇數個網格

  • BAF_ROI_PATTERN_SPARSE

稀疏型

  • grid_size_h

ROIgrid width ratio with respect to ROI width.

  • grid_size_v

ROIgrid height ratio with respect to ROI height.

This number determinesthe number of regions.

每個ROI網格的長寬占整個ROI長寬的比例,默認是0.2.

這個值決定ROI將分成多少個小區域。

  • grid_gap_h

ROIgrid gap width ratio with respect to ROI width.

  • grid_gap_v

ROIgrid 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

gammaoff

關閉Gamma

  • AF_TUNING_PRESET_1

gammacoefficient = 1/2.2

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

  • Custom Gamma

定製gamma使能時需要配置

  • ch_sel

Selectto use green channel only or weighted RGB for Y channel.

Processingchannel selection, 0=G, 1=Y.

選擇FV統計的通道,寫0隻對G通道統計,寫1統計RGB加權後的Y通道。

  • Y_coeffs

Weightfor R, G, B channel respectively to form Y.

Yconversion 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_tdefines the default set for FIR, IIR, and Shifter stored in the AF core. Coring isnot controlled by apreset.

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 tuninginvolves adjusting the Coring Index and the Coring Gain.

核化降噪閾值是輸入核化降噪表中的最大 FV 值。 任何大於該值的 FV 值都僅應用一個增益。濾鏡核化降噪的調試過程將調整核化降噪指數和核化降噪增益。

  • x_index

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

共17個值(單調遞增),表示 [0 - 16]的核化抑制等級

Default is x^3 with lastentry = 16

默認最後一個值等於16, 不知道什麼意思

Coring suppression level at every 1/16 interval of thresholdvalue(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 thenormalized frequency passband of each filter. Filters that have higherpassbands, and hence retain higher frequency content, tend to have longer tailsand 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 offace detection in conjunction with AF. In this case, because faces tend to havemainly low-frequency content, the IIR [0.05-0.12] filter is recommended.However, for scenes containing very small sources of light surrounded byflatness, the IIR [0.2-0.35] filter has shown better results. The choice of thefilter for a particular application depends on the frequency characteristics ofscenes 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 unsigned14-bit format. The bit-shift values indicated in the two tables ensure that thefiltered pixel values are converted to unsigned 18-bit data. The increase inbit width allows the filtered data to have greater precision. The IIR portionsof the filters listed above are designed to have a gain of unity. This meansthat 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 thegain of the FIR section. When a custom FIR filter is used, it is important thatthe bit-shift value be changed according to the gain of the FIR filter toensure 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, b0, b1, b2, a1, a2

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 saturatedpixels

高通濾波,對海岸城多光源場景表現很好,但低亮度場景失敗率很高。

[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

頻率範圍未知,作為備選方案。

  • scaler_sel

縮放使能,寫0不縮放,寫1就以scaler的比例進行縮放再做fv統計。

  • scaler

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

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

M N縮放器,M是輸入尺寸,N是輸出尺寸,M/N就是縮放比例,僅支持整數縮放,最大8/1.

  • M

input size

  • N

output size

相關資料

常用二階IIR濾波係數的計算方法 - eeleader的日誌 - 電子工程世界-論壇

反差式對焦評價函數的頻率特性考慮 - 知乎專欄

傅里葉分析之掐死教程(完整版)更新於2014.06.06 - 知乎專欄

圖解IIR FIR 濾波器在自動對焦中的應用
推薦閱讀:

Camera+ 可否稱得上最棒的攝影類應用?
Android Camera 驅動開發入門必備知識有哪些?
舜宇光學
舜宇光學:相機模組龍頭
Android 上最好的拍照軟體是什麼?系統自帶?Camera Fun Pro?Camera360?Vignette 還是其他?

TAG:Camera | 智能手機 |