简体   繁体   English

从一组图片中检测(并去除)划痕

[英]Detect (and remove) scratches from a set of pictures

To simplify, I have a set of pictures shot from a camera.为简化起见,我有一组用相机拍摄的照片。 This camera was behind an acrylic dome and this dome has scratches on it.这台相机在一个亚克力圆顶后面,这个圆顶上有划痕。 The scratches are very apparent in the pictures.图片中的划痕非常明显。 With opencv, I'm trying to detect and remove these scratches.使用 opencv,我试图检测并去除这些划痕。 My first approach is to multiply a subset of the pictures to create a mask, than apply the inpaint mask.我的第一种方法是将图片的子集相乘以创建蒙版,而不是应用修复蒙版。 Am I on the right track?我在正确的轨道上吗? Is there a treatment I can do on the images before multiplying them?在将它们相乘之前,我可以对图像进行处理吗?

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

EDIT: Here is an image highlighting the scratches编辑:这是一张突出划痕的图像在此处输入图片说明

After a few tests, I came with a reliable way to eliminate recurring scratches and dust spots on a set of images.经过几次测试,我找到了一种可靠的方法来消除一组图像上反复出现的划痕和灰尘斑点。 First, I take a subset of 10 to 15 pictures, open them, and apply sobel derivatives to extract the contours.首先,我取 10 到 15 张图片的子集,打开它们,然后应用sobel 导数来提取轮廓。

        private Image<Gray, byte> GetImageContours(String strImage)
        {
            Image<Gray, Byte> img = new Image<Gray, byte>(strImage);
            Image<Gray, float> gradx = img.Sobel(1, 0, 5);
            Image<Gray, Byte> gradxconv = gradx.ConvertScale<Byte>(1, 0);
            Image<Gray, float> grady = img.Sobel(0, 1, 5);
            Image<Gray, Byte> gradyconv = grady.ConvertScale<Byte>(1, 0);
            Image<Gray, Byte> imgContours = gradxconv.AddWeighted(gradyconv, 0.5, 0.5, 0);

            img.Dispose();
            gradx.Dispose();
            grady.Dispose();
            gradxconv.Dispose();
            gradyconv.Dispose();

            return imgContours;
        }

Then, I convert the images back to a 16bit depth, then multiply all of them.然后,我将图像转换回 16 位深度,然后将它们全部相乘。 This should give me an image of the scratches only.这应该只给我一个划痕的图像。 To create a mask of the scratches, I erode this image one time, then dilate it 10 times.为了创建划痕的蒙版,我腐蚀了这个图像一次,然后将其扩大了 10 次。 After that, I convert it to black and white by running a TresholdBinary with a treshold value of 40.之后,我通过运行阈值为 40 的 TresholdBinary 将其转换为黑白。

The final step is to use the Inpaint function on all the set of images with the scratch mask.最后一步是在所有带有刮擦蒙版的图像集上使用 Inpaint 功能。

            Image<Gray, float> _img1 = img1.Convert<Gray, float>();
            Image<Gray, float> _img2 = img2.Convert<Gray, float>();
            Image<Gray, float> _img3 = img3.Convert<Gray, float>();
            Image<Gray, float> _img4 = img4.Convert<Gray, float>();
            Image<Gray, float> _img5 = img5.Convert<Gray, float>();
            Image<Gray, float> _img6 = img6.Convert<Gray, float>();
            Image<Gray, float> _img7 = img7.Convert<Gray, float>();
            Image<Gray, float> _img8 = img8.Convert<Gray, float>();
            Image<Gray, float> _img9 = img9.Convert<Gray, float>();
            Image<Gray, float> _img10 = img10.Convert<Gray, float>();
            Image<Gray, float> _img11 = img11.Convert<Gray, float>();
            Image<Gray, float> _img12 = img12.Convert<Gray, float>();
            Image<Gray, float> imgMask = _img1.Mul(_img2).Mul(_img3).Mul(_img4).Mul(_img5).Mul(_img6).Mul(_img7).Mul(_img8).Mul(_img9).Mul(_img10).Mul(_img11).Mul(_img12).Erode(1);
            Image<Gray, Byte> imgMask2 = imgMask.Convert<Gray, Byte>();
            Image<Gray, Byte> imgMask3 = imgMask2.Dilate(10).ThresholdBinary(new Gray(40), new Gray(255));

            //img is one of the original images to remove scratches on
            ImageViewer viewer3 = new ImageViewer(img.InPaint(imgMask3, 3), "image3");
            viewer3.Show();

Here are sample images taken at each step:以下是每一步拍摄的示例图像:

original image原图在此处输入图片说明

contours of this image此图像的轮廓在此处输入图片说明

all the contours multiplied所有的轮廓相乘在此处输入图片说明

the mask eroded and dilated面具被侵蚀和扩张在此处输入图片说明

the final result最终结果在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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