How to remove a scratch from an image using matlab

前端 未结 3 750
一整个雨季
一整个雨季 2020-12-11 04:29

Let\'s say I have this image this:

\"enter

With a black scratch and I want to

相关标签:
3条回答
  • 2020-12-11 04:59

    A filter for Avisynth and a plugin for VirtualDub (my two favourite video editing tools). It will hardly get better than these two (You can learn from them if you really need to implement it yourself).

    0 讨论(0)
  • 2020-12-11 05:00

    If you know the location of the scratch, this problem is known as inpainting, 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:

    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: difference between median and original image

    When I binarize this image with a manually selected threshold, I get a quick&dirty scratch detector: Binarized

    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.

    One small improvement is to remove small components: DeleteSmallComponents

    This is still not perfect, but the result is good enough to use it as an inpainting mask: inpainting

    This will remove some detail, too, but the differences are harder to spot.

    Full Mathematica code:

    difference = ImageDifference[sourceImage, MedianFilter[sourceImage, 2]];
    mask = DeleteSmallComponents[Binarize[difference, 0.15], 15];
    Inpaint[sourceImage, mask]
    

    EDIT:

    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 mask*sourceImage + (1-mask)*medialFilteredImage in Matlab). Depending on the image data, the difference might not be worth the extra effort of a "real" inpainting algorithm:

    Poor man's inpainting

    0 讨论(0)
  • 2020-12-11 05:11

    My result using median filter with ImageJ

    0 讨论(0)
提交回复
热议问题