何为坏点?
坏点指的是芯片加工过程中一些电子元器件的损坏,不会呈现图像的像素点,最终效果是图像上的黑点。
坏点产生的原因:
DPC算法的作用:Bayer模式下坏点矫正。
基本POINT算法矫正原理:
坏点往往是一个邻域内极亮或极暗的点,以5*5邻域为检测区域。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%代码---ISP算法的DPC算法(POINT法,用于坏点矫正)
%Author:Zhu
%时间:2022.5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear;
close all;
% --------阈值与扩展的边缘---------
Threshold = 30;
filePath = 'E:\\1.raw';
bayerFormat = 'RGGB';
width = 4096;
height= 3000;
bits = 8;
%%%读取RAW
bayerData = readRaw(filePath, bits, width, height);
figure();
imshow(uint8(bayerData));
title('raw image');
%%%遍历像素点,因为是5个为一个邻域,因此先暂不处理3行边缘
for i=3:1:height-3
for j=3:1:width-3
%%%8邻域像素点
Rc = bayerData(i,j);
R1 = bayerData(i-2,j-2);
R2 = bayerData(i-2,j);
R3 = bayerData(i-2,j+2);
R4 = bayerData(i,j-2);
R5 = bayerData(i,j+2);
R6 = bayerData(i+2,j-2);
R7 = bayerData(i+2,j);
R8 = bayerData(i+2,j+2);
%%%计算中心像素与周围八个像素值的差;
subR_Value1=Rc-R1;
subR_Value2=Rc-R2;
subR_Value3=Rc-R3;
subR_Value4=Rc-R4;
subR_Value5=Rc-R5;
subR_Value6=Rc-R6;
subR_Value7=Rc-R7;
subR_Value8=Rc-R8;
%%%如果插值都大于0或都小于0,则可能是坏点;若差值超过阈值,则一定是坏点
if((subR_Value1>Threshold && subR_Value2>Threshold && subR_Value3>Threshold && subR_Value4>Threshold && subR_Value5>Threshold && subR_Value6>Threshold && subR_Value7>Threshold && subR_Value8>Threshold)||(subR_Value1<-Threshold && subR_Value2<-Threshold && subR_Value3<-Threshold && subR_Value4<-Threshold && subR_Value5<-Threshold && subR_Value6<-Threshold && subR_Value7<-Threshold && subR_Value8<-Threshold))
%%%如果是坏点,则根据中值进行纠正
Sort_Pixel = [R1,R2,R3,R4,R5,R6,R7,R8];
Rc = median(Sort_Pixel);
end
bayerData(i,j) = Pc;
end
end
bayerData = uint8(bayerData);
%%%显示纠正后的Raw图
figure;
imshow(bayerData);
title('correct image');
附上Matlab读取RAW图的程序
function rawData = ReadRaw(fileName, bitsNum, width, height)
fin = fopen(fileName, 'r');
switch bitsNum
case 8
disp('bits: 8');
format = sprintf('uint8=>uint8');
case 10
disp('bits: 10');
format = sprintf('uint16=>uint16');
case 12
disp('bits: 12');
format = sprintf('uint16=>uint16');
case 16
disp('bits: 16');
format = sprintf('uint16=>uint16');
end
I = fread(fin, width*height, format);
z = reshape(I, width, height);
z = z';
rawData = z;
end