Find "noisy" lines in a image with cv2 in python

Question:

I have the following image:
raw example image

What is the best way to find the brown lines?

The output image should kind of look like this:
example image with makeshift lines drawn

I have tried to just filter out the brown color, but I couldn’t find a good color range.

Asked By: Flojomojo

||

Answers:

You might use "Morphological gradient" as a rough indicator of "noisy".

Following 2 images is, "Morphological gradient" (of the grayscaled image) and the binalized result of it.

enter image description here
enter image description here

Although I can not judge whether such a simple preprocessing result is really useful…
If you can use some preconditions, for example

  • The interest region (surrounded by "noisy lines") is enoughly large
  • Orientation of "noisy lines" is always 45 degree
  • etc

You may be able to think some method based on them.
e.g. extracting biggest black region from the binalized image, and then approximating the region’s border as 45 degree line.

Answered By: fana

The brown lines are fairly well separated in HSV colourspace in the H channel. Below the H channel is on the left, the S channel in the centre and V on the right:

enter image description here

Likewise, if you convert to Lab mode, you can discern the brown lines in the a channel. L is on the left, a in the centre and b on the right:

enter image description here

Answered By: Mark Setchell

Ended up taking 3 static points from the image, template matching them and manually setting offsets to calculate the lines

Answered By: Flojomojo