matlab中删除照片,如何使用matlab从图像中删除划痕

Let's say I have this image this:

076ca17ce62562c56985c5db8c5e2b68.png

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:

70bb806d038ee9d73999c0de1425de88.png

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

8C77M.png

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:

8397ac7e24213eed1d740d11a2ab5c71.png

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

6cc63daec0785ec2ef48c9f809e0e998.png

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:

4c14affb78c6ba4c692ea1f68bf06b4b.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值