# 图像处理之坏点校正及源码实现

1、坏点介绍

(1) 静态坏点：分为静态亮点和静态暗点。

(2) 动态坏点：在一定像素范围内，该点表现正常，而超过这一范围，该点表现的比周围像素要亮。与sensor 温度、增益有关，sensor 温度升高或者gain 值增大时，动态坏点会变的更加明 显；

2、坏点校正成因

(1) 如果图像中存在坏点的话，ISP后续进行插值和滤波处理时，会影响周围的像素点值，因此需要在插值和滤波之前对坏点进行校正 ;

(2) 图像存在坏点比较多或动态坏点很多的情况下，会造成图像的边缘出现伪色彩的情况，这种现象不但影响图像的清晰度，而且会影响边缘的色彩;

(3) 坏点也会造成图像部分pixel闪烁的现象;

3、坏点校正策略

4、源码实现(Matlab Version)

close all;

clear;

clc;

%% variable

dp_slope = 0.02;

dp_thresh = -0.3;

% x = 0:255;

% y = dp_slope * x + dp_thresh;

% y(y

% y(y>1) = 1;

% figure,

% plot(0:255,y)

% axis([0 255 0 1.5])

[filename, pathname] = ...

uigetfile({'*.raw'}, 'select picture');

str = [pathname filename];

fp = fopen(str, 'rb');

fclose(fp);

img = uint8(X/16)';

[height, width] = size(img);

img_correct = zeros(height, width);

%% Image edge extension

imgn=zeros(height+2*r,width+2*r);

imgn(r+1:height+r,r+1:width+r)=img;

imgn(1:r,r+1:width+r)=img(1:r,1:width);

imgn(1:height+r,width+r+1:width+2*r+1)=imgn(1:height+r,width:width+r);

imgn(height+r+1:height+2*r+1,r+1:width+2*r+1)=imgn(height:height+r,r+1:width+2*r+1);

imgn(1:height+2*r+1,1:r)=imgn(1:height+2*r+1,r+1:2*r);

%% dp algorithm

for i = r+1:height-r

for j = r+1:width-r

img_r = imgn(i-r:2:i+r, j-r:2:j+r);

data_r_center = img_r(r, r);

data_r_diff(1:r+1, 1:r+1) = abs(img_r - img_r(r,r));

data_r_sort = sort(img_r(:));

data_r_median = data_r_sort(r*2+1);

data_r_detect = data_r_diff * dp_slope + dp_thresh;

data_r_detect(data_r_detect

data_r_detect(data_r_detect > 1) = 1;

data_r_judge = sum(sum(data_r_detect > 0));

data_r_weight = sum(sum(data_r_detect)) / data_r_judge;

if i-r == 18 && j-r == 43

a = 1;

end

if data_r_judge >= 7

data_r_correct = data_r_median * data_r_weight + (1-data_r_weight) * data_r_center;

else

data_r_correct = data_r_center;

end

img_correct(i-r, j-r) = data_r_correct;

end

end

%% show

figure,imshow(uint8(img));

figure,imshow(uint8(img_correct));

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180611B0CEZD00?refer=cp_1026
• 腾讯「云+社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 yunjia_community@tencent.com 删除。

2021-05-11

2021-05-11

2021-05-11

2018-05-04

2018-04-27

2018-04-24

2021-05-11

2021-05-11

2021-05-11

2021-05-11

2021-05-11

2021-05-11