I want to extract horizontal and vertical lines in 2 masks for the attached image.
I have tried morphological operations to do this,
horizontalStructure = cv.getStructuringElement(cv.MORPH_RECT, (horizontal_size, 1))
verticalStructure = cv.getStructuringElement(cv.MORPH_RECT, (1, verticalsize))
But the problem, It detects the line as a rectangle and then draws it in a form of 2 lines representing the 2 sides of the rectangle.
Any ideas to fix that?
The horizontal result:
The vertical result:
EDIT: That's another image I have:




What did you do with your structuring elements? Where's the rest of your code?
I'd suggest to use morphological opening using
cv2.morphologyEx, like so:I get the following two masks, which look quite good to me:
Hope that helps!