如何使用matlab从图像中删除划痕 [英] How to remove a scratch from an image using matlab

查看:777
本文介绍了如何使用matlab从图像中删除划痕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这张图片,并且有非常复杂的算法。因此,一种方法是尽可能好地检测划痕,然后在其上使用标准的修复算法。我在Mathematica中玩了一下你的图像:



首先我对图像应用了中值滤波器。正如您自己发现的那样,这可以消除划痕,但也会消除很多细节。中位数和原始图像之间的差异是一个很好的指标,但是:



当我用手动选择的阈值对这个图像进行二值化时,我得到一个快速且肮脏的刮擦检测器:



如果您对划痕的外观有更多了解,可以改善这一点探测器很多。例如划痕总是黑暗的吗?它们总是具有高对比度吗?它们总是平滑的曲线,即它们的曲率总是很低吗? - 这些属性中的每一个都可以通过某种方式进行测量,因此您可以将这些测量值组合到单个图像中并对其进行二值化。



一个小的改进是删除小组件:



这仍然不完美,但结果足以将其用作修补面具:



这也将删除一些细节,但差异更难以发现。



完整的Mathematica代码:

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

编辑:



如果您无法使用标准的修复算法(如Navier Stokes或Telea),那么穷人的算法就是在这些区域中使用中值滤波图像掩码是1(在Matlab中可能类似于 mask * sourceImage +(1-mask)* medialFilteredImage )。根据图像数据,差异可能不值得真正的修复算法的额外努力:




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

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:

这篇关于如何使用matlab从图像中删除划痕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆