Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
convert image.png -morphology Open Octagon result.png
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.
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
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.
convert noise.tif -morphology Open Disk enhanced.tif
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.