isp 图像算法(二)之dead pixel correction坏点矫正
生活随笔
收集整理的這篇文章主要介紹了
isp 图像算法(二)之dead pixel correction坏点矫正
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
代碼在git
相機(jī)中的壞點(diǎn)就是那些和周圍不一樣的點(diǎn),就是那些數(shù)值極大或者極小值點(diǎn),你可以理解一張曲面的山峰或者山谷,人群中也是一樣,那些與大眾不一樣的人就是"壞人",衡量好壞用他與周圍的差值,
abs[V(好人)-v(壞人)] if (abs(p1 - p0) > self.thres) and (abs(p2 - p0) > self.thres) and (abs(p3 - p0) > self.thres) \and (abs(p4 - p0) > self.thres) and (abs(p5 - p0) > self.thres) and (abs(p6 - p0) > self.thres) \and (abs(p7 - p0) > self.thres) and (abs(p8 - p0) > self.thres):threds=30
那個最優(yōu)秀的人就是壞人,不,是壞pixel
| p6 | p7 | p8 |
| p4 | p0 | p5 |
| p1 | p2 | p3 |
代碼
#!/usr/bin/python import numpy as npclass DPC:'Dead Pixel Correction'def __init__(self, img, thres, mode, clip):self.img = imgself.thres = thresself.mode = modeself.clip = clipdef padding(self):#在四周放兩個0 從(1080,1920) --->(1084,1924)img_pad = np.pad(self.img, (2, 2), 'reflect')return img_paddef clipping(self):#np.clip是一個截取函數(shù),用于截取數(shù)組中小于或者大于某值的部分,并使得被截取部分等于固定值#限定在()0,1023np.clip(self.img, 0, self.clip, out=self.img)return self.imgdef execute(self):img_pad = self.padding()raw_h = self.img.shape[0]raw_w = self.img.shape[1]dpc_img = np.empty((raw_h, raw_w), np.uint16)for y in range(img_pad.shape[0] - 4):for x in range(img_pad.shape[1] - 4):p0 = img_pad[y + 2, x + 2]p1 = img_pad[y, x]p2 = img_pad[y, x + 2]p3 = img_pad[y, x + 4]p4 = img_pad[y + 2, x]p5 = img_pad[y + 2, x + 4]p6 = img_pad[y + 4, x]p7 = img_pad[y + 4, x + 2]p8 = img_pad[y + 4, x + 4]if (abs(p1 - p0) > self.thres) and (abs(p2 - p0) > self.thres) and (abs(p3 - p0) > self.thres) \and (abs(p4 - p0) > self.thres) and (abs(p5 - p0) > self.thres) and (abs(p6 - p0) > self.thres) \and (abs(p7 - p0) > self.thres) and (abs(p8 - p0) > self.thres):if self.mode == 'mean':p0 = (p2 + p4 + p5 + p7) / 4elif self.mode == 'gradient':dv = abs(2 * p0 - p2 - p7)dh = abs(2 * p0 - p4 - p5)ddl = abs(2 * p0 - p1 - p8)ddr = abs(2 * p0 - p3 - p6)if (min(dv, dh, ddl, ddr) == dv):p0 = (p2 + p7 + 1) / 2elif (min(dv, dh, ddl, ddr) == dh):p0 = (p4 + p5 + 1) / 2elif (min(dv, dh, ddl, ddr) == ddl):p0 = (p1 + p8 + 1) / 2else:p0 = (p3 + p6 + 1) / 2dpc_img[y, x] = p0self.img = dpc_imgreturn self.clipping()總結(jié)
以上是生活随笔為你收集整理的isp 图像算法(二)之dead pixel correction坏点矫正的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux驱动由浅入深系列链接
- 下一篇: isp 图像算法(四)之white ba