Well, the most logical way is to iterate over the whole picture, then get the values of max and min pixels. Then select a threshold that will give you the desired percentage (1% in your case). After that, try again and save the i and j coordinates for each pixel above the specified threshold. Thus, you will iterate over the matrix only twice instead of 100 (or 1% of the pixel time) and select the brightest one and delete it.
OpenCV mats are multidimensional arrays. The gray image is a two-dimensional array with values from 0 to 255. You can iterate through a matrix like this. for(int i=0;i < mat.height();i++) for(int j=0;j < mat.width();j++) mat[i][j];
Petar velev
source share