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σ].
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 )
source share