Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect points which are drastically different than their neighbours

I'm doing some image processing, and am trying to keep track of points similar to those circled below, a very dark spot of a couple of pixels diameter, with all neighbouring pixels being bright. I'm sure there are algorithms and methods which are designed for this, but I just don't know what they are. I don't think edge detection would work, as I only want the small spots. I've read a little about morphological operators, could these be a suitable approach?

Thanks

wavelet filtered image

like image 961
Simonw Avatar asked Aug 06 '10 16:08

Simonw


7 Answers

Loop over your each pixel in your image. When you are done considering a pixel, mark it as "used" (change it to some sentinel value, or keep this data in a separate array parallel to the image).

When you come across a dark pixel, perform a flood-fill on it, marking all those pixels as "used", and keep track of how many pixels were filled in. During the flood-fill, make sure that if the pixel you're considering isn't dark, that it's sufficiently bright.

After the flood-fill, you'll know the size of the dark area you filled in, and whether the border of the fill was exclusively bright pixels. Now, continue the original loop, skipping "used" pixels.

like image 193
Tom Sirgedas Avatar answered Oct 05 '22 12:10

Tom Sirgedas


How about some kind of median filtering? Sample values from 3*3 grid (or some other suitable size) around the pixel and set the value of pixel to median of those 9 pixels.

Then if most of the neighbours are bright the pixel becomes bright etc.

Edit: After some thinking, I realized that this will not detect the outliers, it will remove them. So this is not the solution original poster was asking.

like image 25
Juha Syrjälä Avatar answered Oct 05 '22 11:10

Juha Syrjälä


Are you sure that you don't want to do an edge detection-like approach? It seems like a comparing the current pixel to the average value of the neighborhood pixels would do the trick. (I would evaluate various neighborhood sizes to be sure.)

like image 28
Eric Brown Avatar answered Oct 05 '22 12:10

Eric Brown


Personally I like this corner detection algorithms manual.

Also you can workout naive corner detection algorithm by exploiting idea that isolated pixel is such pixel through which intensity changes drastically in every direction. It is just a starting idea to begin from and move on further to better algorithms.

like image 45
Agnius Vasiliauskas Avatar answered Oct 05 '22 11:10

Agnius Vasiliauskas


I can think of these methods that might work with some tweaking of parameters:

  • Adaptive thresholds
  • Morphological operations
  • Corner detection
like image 27
Utkarsh Sinha Avatar answered Oct 05 '22 12:10

Utkarsh Sinha


I'm actually going to suggest simple template matching for this, if all your features are of roughly the same size.

Just copy paste the pixels of one (or a few features) to create few templates, and then use Normalized Cross Correlation or any other score that OpenCV provides in its template matching routines to find similar regions. In the result, detect all the maximal peaks of the response (OpenCV has a function for this too), and those are your feature coordinates.

like image 23
karpathy Avatar answered Oct 05 '22 12:10

karpathy


Blur (3x3) a copy of your image then diff your original image. The pixels with the highest values are the ones that are most different from their neighbors. This could be used as an edge detection algorithm but points are like super-edges so set your threshold higher.

what a single off pixel looks like:
(assume surrounding pixels are all 1)

original  blurred         diff
1,1,1     8/9,8/9,8/9     1/9,1/9,1/9
1,0,1     8/9,8/9,8/9     1/9,8/9,1/9
1,1,1     8/9,8/9,8/9     1/9,1/9,1/9


what an edge looks like:
(assume surrounding pixels are the same as their closest neighbor)

original  blurred         diff
1,0,0     6/9,3/9,0/9     3/9,3/9,0/9
1,0,0     6/9,3/9,0/9     3/9,3/9,0/9
1,0,0     6/9,3/9,0/9     3/9,3/9,0/9
like image 43
dtudury Avatar answered Oct 05 '22 12:10

dtudury