0

I am trying to get a small scratch from the noise image as shown. It is quite noticeable by eyes, but I would like to identify it using OpenCV Python.

I tried to use image blurring and subtract it from the original image, and then threshold to get a image as the second.

Could any body please advise to get this scratch?

Original image:

Original image

Image after blurring, subtraction, and threshold:

Image after blurring, subtraction, and threshold

This is how I process this image:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread("scratch0.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.blur(gray,(71,71))

diff = cv2.subtract(blur, gray)
ret, th = cv2.threshold(diff, 13, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("threshold", th)
cv2.waitKey(0)
Xinlong Wang
  • 11
  • 1
  • 4
  • You could perform line detection after your blurring-subtraction-threshold procedure. – PlinyTheElder Sep 19 '19 at 13:26
  • I tried cv2.findContours but got many small features, not the line, maybe because the gray scale of remaining pixels are too close or there are missing pixels alone the line. Is there anyway to strengthen pixels on the line or reduce the pixels outside the line? – Xinlong Wang Sep 20 '19 at 09:14
  • Nah, don't use `findContours`, just use the Hough Line Detection - it should find the line. – PlinyTheElder Sep 20 '19 at 13:36
  • It is very hard to find the line(actually a small area), because there are many small features around the target area. The gray scale of these small features is very close to the gray scale of those scratch pixels. – Xinlong Wang Sep 21 '19 at 16:00
  • Definitely. You'll need to look for the line on the image after blurring, subtraction, threshold I think. Good luck. – PlinyTheElder Sep 22 '19 at 14:38

0 Answers0