Javascript Dead Pixel Algorithm

I am trying to create an algorithm that detects and counts dead pixels from an intensity map in .csv format. My current approach is to split the pixel value that I am testing into the pixel value immediately on the right (or, if on the right side, on the left). If the dividend is less than some threshold (currently .9), then I mark it as a dead pixel.

My question is: is there a better / more efficient way to calculate if the pixel is dead?

Example csv output:

3183 3176 3207 3183 3212 3211 3197 3198 3183 3191 3193 3177 1135 3185 3176 3175 3184 3188 3179 3181 3181 3165 3184 3187 3183 

In this example, the middle pixel will be a dead pixel.

+6
source share
4 answers

Efficiency

You will need to look at each pixel at least once, so you cannot normally use the current O (n) , where n is the number of pixels. Your algorithm uses a constant amount of memory, which is also optimal.

However, I'm not sure your algorithm is always right. Do you have a way to avoid comparing consecutive dead pixels? Input Example:

 3183 3176 1135 1135 3212 ^ Not detected 

More accurate way

I assume that you take the intensity of a neighboring pixel to avoid comparing pixels located in different areas of the screen, since the brightness of the screen can be unevenly distributed.

One way to avoid false negatives is to accept the average of several neighboring pixels, but this may not work if there are a lot of dead pixels in the area. You can try to take the maximum value of all the pixels in a small area. Thus, until one pixel in the entire area is dead, all dead pixels will be detected.

How many pixels you choose will be determined by your tolerance for false negatives.

+2
source

Your current approach will not help you if you have a cluster of dead pixels. It may also incorrectly interpret a stuck pixel (a pixel with 100% intensity) as a valid pixel and the surrounding pixel as a defect, depending on the image used to check the screen.

Instead, calculate the total average μ and variance σ 2 of your data and interpret the data as normal distribution . According to rule 68-95-99.7 , 95% of all data should be in the range [μ-2σ, μ + 2σ].

Standard derivation diagram

Let's look at your sample and determine if this is true for your data:

 var arr = "5000 3176 3207 3183 3212 3211 3197 3198 3183 3191 3193 3177 1135 3185 3176 3175 3184 3188 3179 3181 3181 3165 3184 3187 3183".split(" "); var i = 0; var avg = 0; // average/mean var vri = 0; // variance var sigma; // sqrt(vri) for(i = 0; i < arr.length; ++i){ arr[i] = parseInt(arr[i]); avg += arr[i]; } avg /= arr.length; for(i = 0; i < arr.length; ++i){ vri += (arr[i]-avg)*(arr[i]-avg); } vri /= (arr.length - 1); sigma = Math.sqrt(vri); for(i = 0; i < arr.length; ++i){ if(Math.abs(arr[i]-avg) > 2*sigma) console.log("entry "+i+" with value "+arr[i]+" probably dead"); } 

This will lead to the detection of dead pixels (8% of the total number of pixels). Note that I also added a very high intensity pixel, which was probably stuck:

  entry 0 with value 5000 propably dead
 entry 12 with value 1135 probably dead 

However, there is one major drawback, since this approach will only work if the screen is equally lit. Also, a stuck pixel cannot be detected if you recorded an intensity map with a simple white image. And, of course, if your data is scattered because the screen is completely broken, this approach will not help you. In addition, it is easy to implement. You can also add a local check to filter out false positives.

Note that this algorithm has a fixed runtime of 3*n .

( diagram was created by Mwtoews )

+2
source

It seems likely that you may have a legitimate sharp transition from light to dark or vice versa / vice versa in a real image - a sharp line of shadow that goes to the bright sun or only to the edge of a white object on a black background. Thus, looking only at the pixel to the right, false positives can easily be created.

What would be less likely to produce a false result would be to compare a pixel with at least each of the four pixels around it (top, bottom, left, right). You would allow a sharp difference between one pixel and two of the four neighbors, but not a sharp difference between one pixel and all four neighbors, since this one pixel feature in a real image would be very unlikely.

You could further eliminate false positives if you need a pixel to skip the test on several separate images (different items).

As for the details on how to do this, you can either do something similar, as you already suggested, but compare with all four neighbors or google search for a “dead pixel detection algorithm” gives a lot of articles on various ideas.

+1
source

if this is the real question (and we are talking about dead pixels in the camera):

take about 5 shots. if a pixel has a significant different intensity from its neighbors (e.g. 11x11 block average, compare RGB separately) in most shots, it is almost certainly dead / stuck.

-1
source

Source: https://habr.com/ru/post/921641/


All Articles