I would like to be able to analyze the following image, get the lines and find the average width.(My copy is much larger ~5K by ~4K) Cannot move to the next step due to all the noise after thresholding.
Using my code I was able to get to this point...
My issue is that it has a lot of noise in-between lines, which looks like noise that got condensed.
Here is my code...
image = np.copy(origImg)
newImage = np.empty_like(image)
scale = 64
height = image.shape[0]
width = image.shape[1]
dH = int(height / scale)
dW = int(width / scale)
xi = int(dH)
yi = int(dW)
fragments = []
image = cv2.bilateralFilter(image,9,75,75)
image = cv2.medianBlur(image, 21)
for i in range(0,height,dH):
for j in range(0,width,dW):
fragment = image[i:i + int(dH), j:j + int(dW)]
fragment = cv2.adaptiveThreshold(fragment, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 0)
fragments.append(fragment)
analyzed = com.stackArrayToImage(fragments)
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(analyzed, None, None, None, 8, cv2.CV_32S)
sizes = stats[1:, -1]
img2 = np.zeros((labels.shape), np.uint8)
for i in range(0, nlabels - 1):
if sizes[i] >= 100:
img2[labels == i + 1] = 255
analyzed = cv2.bitwise_not(img2)
analyzed = cv2.erode(analyzed, np.ones((5, 5)), iterations=2)
analyzed = cv2.dilate(analyzed, np.ones((5, 5), np.uint8))
dis.plotImages([origImg], "Origional")
dis.plotImages([analyzed], "Analyzed")
dis.displayStart()
Is there anyway I can remove that noise?
Thank you very much!




