How to detect and fix dead pixels in images using

2019-06-04 10:38发布

问题:

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?

回答1:

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 :