There is a noisy and blurry image that contains an edge that must be detected. The edge is clearly visible to the human eye, but I'm having trouble letting OpenCV detect it. The image in question: bad quality image. You need to adjust the contrast and brightness to see it. I only wanted to post the original image.
The edge that is to be detected is the thick black one that runs horizontally, after the ROI is applied. Here is what I have tried so far:
import numpy as npfrom PIL import Imageimport cv2file = "input3.tif"im = Image.open(file)imarray = np.array(im)roi = imarray[230:310, 460:660]img8 = (roi/2).astype('uint8')cv2.imshow('img8', img8)blur = cv2.bilateralFilter(img8,9,5,150)cv2.imshow('blur', blur)kernel = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]])sharpened = cv2.filter2D(blur, -1, kernel)cv2.imshow('sharpened', sharpened)edges = cv2.Canny(sharpened,150, 250, apertureSize=3)lines = cv2.HoughLinesP(edges, 1, np.pi/180, 20, minLineLength=100, maxLineGap=8)for line in lines: for x1, y1, x2, y2 in line: cv2.line(img8, (x1, y1), (x2, y2), (0, 0, 255), 2)cv2.imshow('out', img8)
With the undesired result.
What improvements can be made so that only the horizontal edge is detected?