Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you know the location of the scratch, this problem is known as <a href="http://en.wikipedia.org/wiki/Inpainting" rel="noreferrer">inpainting</a>, and there are very sophisticated algorithms for that. So one approach would be to detect the scratch as good as you can, then use a standard inpainting algorithm on it. I've played with your image in Mathematica a little:</p> <p>First I applied a median filter to the image. As you found out yourself, this removes the scratch, but also removes a lot of detail. The difference between median and original image is a good indicator for your scratch, though: <img src="https://i.stack.imgur.com/OnCCl.png" alt="difference between median and original image"></p> <p>When I binarize this image with a manually selected threshold, I get a quick&amp;dirty scratch detector: <img src="https://i.stack.imgur.com/8C77M.png" alt="Binarized"></p> <p>If you have more knowledge about what your scratches look like, you can improve this detector a lot. e.g. are the scratches always dark? Do they always have high contrast? Are they always smooth curves, i.e. is their curvature always low? - Each of these properties can be measured somehow, so you'd combine these measurements to a single image and binarize that.</p> <p>One small improvement is to remove small components: <img src="https://i.stack.imgur.com/Libx5.png" alt="DeleteSmallComponents"></p> <p>This is still not perfect, but the result is good enough to use it as an inpainting mask: <img src="https://i.stack.imgur.com/Stlsi.png" alt="inpainting"></p> <p>This will remove some detail, too, but the differences are harder to spot.</p> <p>Full Mathematica code:</p> <pre><code>difference = ImageDifference[sourceImage, MedianFilter[sourceImage, 2]]; mask = DeleteSmallComponents[Binarize[difference, 0.15], 15]; Inpaint[sourceImage, mask] </code></pre> <p><strong>EDIT:</strong></p> <p>If you're don't have access to a standard inpainting algorithm (like Navier Stokes or Telea), a poor man's algorithm would be to use the median filtered image in those regions where the mask is 1 (probably something like <code>mask*sourceImage + (1-mask)*medialFilteredImage</code> in Matlab). Depending on the image data, the difference might not be worth the extra effort of a "real" inpainting algorithm:</p> <p><img src="https://i.stack.imgur.com/UqFlR.png" alt="Poor man&#39;s inpainting"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload