上一篇文章講的是:ISP Pipeline(2): Black Level Compensation:ISP Pipeline(2):Black Level Compensation 黑電平補償-CSDN博客
視頻:(4) Lens Shading Correction | Image Signal Processing Pipeline Tutorial Series
源碼:AI_Plays/ISP/Fast_ISP_Progress.ipynb at main · ameengee/AI_Plays · GitHub
Lens Shading Correction(LSC) 是 ISP(圖像信號處理)中的一個重要步驟,用來校正由于鏡頭和圖像傳感器組合所導致的圖像亮度和顏色在空間分布上的不均勻性問題。這個問題在 廣角鏡頭、低光照環境或者大光圈 情況下尤為明顯。
為什么需要 LSC?
拍攝的原始圖像中,常見問題如下:
-
中心亮,邊緣暗(vignetting);
-
顏色偏差(不同通道光線衰減不一樣,比如邊緣區域紅色多,綠色少);
-
會影響白平衡、顏色還原、圖像質量。
成因
主要包括:
-
鏡頭透鏡結構:光線穿過鏡頭時,邊緣光線容易損失。
-
光線入射角不同:邊緣像素光線入射角更大,靈敏度降低。
-
傳感器非線性響應:傳感器各位置像素響應不一致。
校正原理(LSC基本思路)
-
預先標定(Calibration):
-
使用均勻光源(integrating sphere)拍攝參考圖,獲得理想圖像亮度/顏色分布。
-
得到一個 增益表(Gain Table),通常按 RGB 分別生成。
-
-
應用校正(Correction):
-
實際圖像中每個像素按其位置(通常是離中心距離)查表得到對應增益值。
-
對每個像素進行乘法修正:
其中 G(x,y)G(x,y) 為增益因子,I 是原像素值,I′ 是校正后的像素值。
-
?代碼實現:
- 計算圖像中心(+1 是為了防止出現 division by zero 或讓中心處不為0,實際可調)。
- 構造每個像素到圖像中心的徑向距離圖,這就是光照衰減的模擬基準。
- 限制中心區域的最小半徑為 1300,意味著只有距離中心大于1300像素的區域才會被增強,中心區域保持不變(增強倍數為
k * 1300 + 1
)。 -
lsc_img = (blc_img * (k * radial_dist + 1) - offset).astype(np.uint16)這個公式可以理解為:
?-
k * r + 1
:讓中心附近是1
,遠離中心增益越來越大; -
offset
是全局亮度調整,防止變得太亮。 -
轉為
uint16
,保留高位數據。
-
def LSC(blc_img, k, offset):"""inputs:blc_img = bayer domain image after black level compensationk = correction factor to control strength of the correctionoffset = offset in case the final image is too brightoutputs:lsc_img = bayer domain image adjusted for lens shading"""rows, cols = blc_img.shapecenter_x = (cols // 2) + 1 # identify center if the imagecenter_y = (rows // 2) + 1x, y = np.meshgrid(np.arange(cols), np.arange(rows)) # create an array where each index is the radial distance from the centerradial_dist = np.sqrt((x - center_x)**2 + (y - center_y)**2)radial_dist = np.where(radial_dist <= 1300, 1300, radial_dist) # ensure correction only applies on the outer edgeslsc_img = (blc_img * (k * radial_dist + 1) - offset).astype(np.uint16) # apply correctionreturn lsc_img