2

I've used this alghoritm http://www.codeproject.com/Articles/336915/Connected-Component-Labeling-Algorithm to clean an image frome noise. This is the original noise enter image description here

And this is what I obtain:

enter image description here

There is still noise around the final image. Does anyone know where the algorithm fails or can recommend a more efficient algorithm? Thank you

Gangnus
  • 24,044
  • 16
  • 90
  • 149
Martina
  • 791
  • 1
  • 14
  • 26
  • Separating signal from noise is a classical non-trivial task. You'll need some deeper understanding of this (or other similar algorithms) before you are able to optimize it for your task at hand. You can't expect "perfect" noise removal, just a "better" hit rate, e.g. lower probability for errors if you work long and hard enough on the optimizations. – DrKoch Feb 26 '15 at 09:43
  • As far as I can see, the remaining noise is limited to within the convex hull of the large blob. Consider whether this property (given it can be verified) would mark a sufficient despeckling quality for your application. – collapsar Feb 26 '15 at 10:14

2 Answers2

3

ImageMagick does a pretty good job of it with minimal effort. It is installed on most Linux distros anyway and available for OSX and Windows. Run from the commandline like this:

convert input.png                                   \
   -colorspace gray -negate -threshold 10%          \
   -define connected-components:verbose=true        \
   -define connected-components:area-threshold=800  \
   -connected-components 8 -auto-level output.png

Output

Objects (id: bounding-box centroid area mean-color):
  0: 431x424+0+0 209.2,207.5 135697 srgb(13,13,13)
  109: 236x273+120+84 231.7,223.0 47047 srgb(255,255,255)

enter image description here

If you change the threshold to only show blobs with an area greater than, say 50, you get this:

Objects (id: bounding-box centroid area mean-color):
  0: 431x424+0+0 210.2,208.5 134262 srgb(11,11,11)
  109: 236x273+120+84 231.7,223.0 47047 srgb(255,255,255)
  1: 40x20+1+1 16.9,9.5 605 srgb(255,255,255)
  190: 12x15+309+153 314.2,160.1 126 srgb(253,253,253)
  83: 12x13+142+71 148.1,76.7 90 srgb(255,255,255)
  164: 12x17+140+132 146.0,140.1 90 srgb(255,255,255)
  347: 10x12+50+304 54.5,309.6 85 srgb(255,255,255)
  440: 11x11+278+399 282.6,404.2 79 srgb(255,255,255)
  448: 6x15+425+403 427.9,409.9 71 srgb(255,255,255)
  151: 9x11+145+122 149.2,126.4 68 srgb(255,255,255)
  93: 11x9+105+75 110.1,79.6 61 srgb(255,255,255)
  170: 9x10+91+136 95.1,140.8 58 srgb(255,255,255)
  258: 9x10+107+220 110.8,225.1 52 srgb(255,255,255)
  53: 10x8+64+47 68.5,50.2 50 srgb(255,255,255)

enter image description here

Alternatively, if you want some C code, you could look at my answer here to this question:

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
2

The algorithm mentioned is NOT mentioned for noise cleaning. The algorithm separates different continuous areas.

You have decided to use the algorithm for to find and separate the main blot. Why not. But it seems, you have found several close small blots, too. As it is, it seems that your prog takes 2-pixel distance as 1-pixel instance. The reasons could be:

  1. errors in code - but hardly can I imagine errors that could result in such picture. Only if you use some additional algorithm for quickening the process. Or, if you are looking for neighbours by simply looking for +1, -1 for x, y in different combinations (the bad way!), you could write 2 instead.
  2. really these small blots ARE connected to the main one by thin sequences of pixels, invisible in the scale you use to show the picture. Is it really 1:1 image?
Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • Maybe there are some errors in the code. Can you reccomand me some algorithm to to find and separate the main blot, please? – Martina Feb 26 '15 at 11:34
  • 1
    But the algorithm is not bad. Is it really 1:1 image? And look for your +1-1 variations when you are looking for neighbours? But what shall you do if the main blot will look as two separate by width of 1 pixel blots? I can't advice you an algorithm not knowing the character of noise. – Gangnus Feb 26 '15 at 11:39
  • the first image (with noise) is zoomed, the second image (the output without noise) is 1:1. If I change (in the class CLL, in the function GetNeighboringLabels) i <= pix.Position.Y + 2 and j <= pix.Position.X + 2 with i <= pix.Position.Y + 1 and j <= pix.Position.X + 1 everything works. It seems strange... – Martina Feb 26 '15 at 14:11
  • 1
    @MartinaLabMath What is strange? You have to check as neighbouring the x+-1, y+-1 pixels. And not +-2. If you consider +-2 points as neighbouring because of your understanding of noise, then your result is simply correct one. And don't do comparison this way. Put all combinations of +-1 into an array and make a cycle through it. – Gangnus Mar 02 '15 at 08:28