Hi,
Anyone know how to remove the scattered small spots in an image? Like below:
Thanks.
How to remove scattered spots in an image?
How to remove scattered spots in an image?
Last edited by calvi on 2011-04-07T23:52:10-07:00, edited 1 time in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How to remove scattered spots in an image?
Try using a -morphology Open function with a 'kernel' that is just a little bigger that the spots.
http://www.imagemagick.org/Usage/morphology/#open
Normally 'Close' is used to remove spots.
http://www.imagemagick.org/Usage/morphology/#close
Nut your image is inverted to the normal usage of greyscale shapes (white on black) so you need to use the negative equivalent, 'Open'
Alternative use 'Smooth' which cleans up both positive and negative images.
PS: yes you image is greyscale and not binary, that is not a problem.
Someone may suggest using 'floodfill'.. DON'T That will remove the grayscale anti-aliasing edge pixels.
http://www.imagemagick.org/Usage/morphology/#open
Code: Select all
convert image.png -morphology Open Octagon result.png
http://www.imagemagick.org/Usage/morphology/#close
Nut your image is inverted to the normal usage of greyscale shapes (white on black) so you need to use the negative equivalent, 'Open'
Alternative use 'Smooth' which cleans up both positive and negative images.
PS: yes you image is greyscale and not binary, that is not a problem.
Someone may suggest using 'floodfill'.. DON'T That will remove the grayscale anti-aliasing edge pixels.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How to remove scattered spots in an image?
Hi Anthony,
Thanks for your help.
I guess this method may affect the sharpness of the edge.
Do you think it is possible to trace the contour and fill the inside?
Thank.
Thanks for your help.
I guess this method may affect the sharpness of the edge.
Do you think it is possible to trace the contour and fill the inside?
Thank.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to remove scattered spots in an image?
morphology open/close should not change smoothness, I don't believe, and is likely your best bet. You can also iterate with a small kernel shape. But your image(s) have white spots on the edge. So trying to get the boundary may have just as many problems. But Anthony has some examples, if I recall. See http://www.imagemagick.org/Usage/transform/#edge_vector
try this:
convert image.enhance.png -morphology open diamond:2 image.enhance_open2.png
seems to fill in all your holes.
try this:
convert image.enhance.png -morphology open diamond:2 image.enhance_open2.png
seems to fill in all your holes.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How to remove scattered spots in an image?
Fred is right.
The operators while originally designed for binary images, work just fine for grayscale images. The greyscale edge will not be lost or destroyed, though some grey edge pixels may move, be removed, or duplicated, according to the kernel fill shape.
Seems to work just fine at preserving the greyscale edge.
Note when I tried the octagon on one of the above shapes some of the edges were 'connected' to the image edge more solidly. Adding a -virtual-pixel white will ensure that IM things the image proper is surrounded by white, and so help prevent that problem. Better still add some white border first.
It will also smooth the 'dents' and small gaps in the edge, and the sharpness of the inside corner as well.
The operators while originally designed for binary images, work just fine for grayscale images. The greyscale edge will not be lost or destroyed, though some grey edge pixels may move, be removed, or duplicated, according to the kernel fill shape.
Seems to work just fine at preserving the greyscale edge.
Note when I tried the octagon on one of the above shapes some of the edges were 'connected' to the image edge more solidly. Adding a -virtual-pixel white will ensure that IM things the image proper is surrounded by white, and so help prevent that problem. Better still add some white border first.
It will also smooth the 'dents' and small gaps in the edge, and the sharpness of the inside corner as well.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How to remove scattered spots in an image?
Hi Anthony, Fred,
Thanks for your quick and great help.
I have tried "morphology" and found it is perfect and introduces no edge blur, like below:
The command used is:
The noisy image is .tif. If it is .png, then the result image will be light grey, not black. I have no idea why. Maybe it is not suitable for .png files.
Sorry that doubt without trying.
Thanks.
Thanks for your quick and great help.
I have tried "morphology" and found it is perfect and introduces no edge blur, like below:
The command used is:
Code: Select all
convert noise.tif -morphology Open Disk enhanced.tif
Sorry that doubt without trying.
Thanks.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How to remove scattered spots in an image?
The TIF to PNG problems is likely to be something to do with TIF and its color handing
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/