简体   繁体   中英

How to remove a scratch from an image using matlab

Let's say I have this image this :

在此处输入图片说明

With a black scratch and I want to remove it from my image. I know it is noise. I have tried neighbourhood filter and also gaussian filter but no success.

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: 中位数和原始图像之间的差异

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

If you have more knowledge about what your scratches look like, you can improve this detector a lot. eg are the scratches always dark? Do they always have high contrast? Are they always smooth curves, ie 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: 修补

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:

穷人的绘画

My result using median filter with ImageJ

在此处输入图片说明

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM