How to detect and fix dead pixels in images using OpenCV?

时间:2015-11-12 11:44:50

标签: c++ opencv image-processing camera

I have some images that they have dead pixels (or pixels that has bad result) I have raw data (bayered data).

enter image description here

How can I detect and fix them using OpenCV?

I tried to fix them using a filter on bayer data. In my algorithm, I detect the color of each pixel and if it was green used an X pattern to find neighboring green pixels and if the value of current pixel is more than say 40 of the neighboring pixels, the pixel value changes by average of neighboring pixels.

did the same things for red and blue using + pattern.

But it did not fix the issue.

Any algorithm which can fix these dead pixels?

1 个答案:

答案 0 :(得分:3)

我建议您为此目的使用median filter

  

C ++:void medianBlur(InputArray src,OutputArray dst,int ksize)

过滤器的优点是它不是卷积。它不会处理操作(没有意思,你的邻居之间没有平均计算)它只会从邻域获取一个像素值(这正是你的邻居像素数组的中值)。

例如,在一个图像(一个颜色通道)上给出一个3x3窗口:

155 153  2    <- Noise here on the 3rd column
148 147 146
144  0  146   <- Noise here on the 2nd column

我们想获得一个介于144155之间的像素值吗?

如果我们使用mean filter,我们会计算平均值:(155+153+2+148+147+146+144+0+146)/9 = 116,这与现实不是很接近。这就是你似乎做的事情,因此是一个不令人满意的结果。

如果我们使用median filter,我们会在以下排序像素[0,2,144,146,146,147,148,153,155]中选择中值 发现的中位数 146 ,更接近现实!

这里是一个中值过滤结果的示例,内核大小为3x3

enter image description here enter image description here

在图片上使用相同的过滤器,我得到:

enter image description here