如何使用OpenCV检测和修​​复图像中的死像素? [英] How to detect and fix dead pixels in images using OpenCV?

查看:272
本文介绍了如何使用OpenCV检测和修​​复图像中的死像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些图像,他们有死像素(或像素,有坏的结果)我有原始数据(分割数据)。





如何检测和修复它们OpenCV?



我试图使用拜耳数据上的过滤器来修复它们。在我的算法中,我检测每个像素的颜色,并且如果它是绿色的,则使用X图案来找到相邻的绿色像素,并且如果当前像素的值大于40个相邻像素,则像素值根据相邻像素的平均值



使用+模式对红色和蓝色做了相同的事情。



但它没有解决这个问题。



任何可以修复这些死像素的算法?

解决方案

我建议您使用



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




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

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?

解决方案

I would suggest you to use a median filter for that purpose.

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

The advantage of the filter is that it is not a convolution. It will not process operation (no mean, no average computation among your neighbors) it will just take one pixel value from the neighbourhood (which is exactly the median value of your neighbours pixel array).

For instance given a 3x3 window on one image (one color channel) :

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

We would like to get a pixel value which would be between 144 and 155 right ?

If we use a mean filter we compute the average : (155+153+2+148+147+146+144+0+146)/9 = 116 which is not a close value to the reality. This is what you seem to do hence an unsatisfiying result.

If we use a median filter, we choose the median values among the following sorted pixels [0,2,144,146,146,147,148,153,155]
The median found is 146 which is closer to the reality !

Here an example of a median filter result with a 3x3 kernel size :

Using the same filter on your image I get :

这篇关于如何使用OpenCV检测和修​​复图像中的死像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆