Removing dust spots from JPG's?

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?".
Post Reply
lwhistler
Posts: 23
Joined: 2010-09-15T15:33:29-07:00
Authentication code: 8675308

Removing dust spots from JPG's?

Post by lwhistler »

Does anyone have any ideas on removing dust spots from JPG's? Similar to using the GIMP clone tool. This is what I have in mind:
  • In GIMP create mask that covers entire image, except for area next to the dust spot(s)
  • Copy original image and add mask.
  • Merge masked image and original image. BUT shift masked image so that unmasked areas are over dust spot.
Is there a better way? Thanks



--------
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing dust spots from JPG's?

Post by fmw42 »

try my isonoise script below or

1)create mask -- white where image and black where noise
2)do median filtering of whole image
3) composite the original and the median filtered version with the mask so that the mask gives back the original except where noise (black in mask) and there it uses the median filtered image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Removing dust spots from JPG's?

Post by anthony »

The key to good 'spot' removal is how to determine the replacement colors.

You may like to look at this old article on 'text removal' which is basically the same method as what Fred describes. It looked at using morphology, and blur to determine colors,
viewtopic.php?p=41498#p41498

A similar method (using blur) is described in IM examples..
http://www.imagemagick.org/Usage/photos/#removing

A new technique, is to extract the pixels around the unwanted area and use -sparse-color to 'diffuse' just the edge pixels into the undesired parts. That is then used with the mask to replace the unwanted parts.

This example is sort of the reverse (fill inward rather than fill outward) of what you want..
http://www.imagemagick.org/Usage/canvas/#sparse_fill

Eventually I hope to make a very easy 'diffusion' method for filling 'holes' that will make this type of thing VERY easy.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lwhistler
Posts: 23
Joined: 2010-09-15T15:33:29-07:00
Authentication code: 8675308

Re: Removing dust spots from JPG's?

Post by lwhistler »

Thanks for the replies, it will take me a while to study fmw42 scripts, you have a lot there. After a quick look the Zelda example - http://www.imagemagick.org/Usage/photos/#removing - looks good and I have it working in a loop on multiple images. Except I get a small black artifact in the dust spot, but so far it looks very promising.

I will post back when I have it working 100%.


Len
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Removing dust spots from JPG's?

Post by anthony »

Note that JPEG is lossy. That 'dust spot' may be larger than expected, whcih would result in
a slight discolouration if your removal mask does nto cover them properly.

You can use morphology to enlarge the mask by a pixel, see if that helps!
http://www.imagemagick.org/Usage/morphology/#basic
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Removing dust spots from JPG's?

Post by Bonzo »

I did try dust removal and from memory the process was:

Locate the spots and put the centers into an array

Mask all the spots with a fuzzy edge and cut out

Copy the original image and blur it than paste the imge with holes over the blured image

It worked quite well but I wanted to automate it on CR2 RAW images and IM didn't handle my RAW files very well.
Post Reply