Rosa
Rosa

Reputation: 165

How can I remove lines (detected by HoughLines) from the image?

I followed (and modified) the method from the best-rated answer of this post.

My image is a little bit different. I used HoughLinesP and managed to detect the majority of red lines. enter image description here

I was wondering is there a way to remove detected lines from the image, without damage to the other black intersecting lines? I am interested in black lines only. Is there a smarter way to isolate black lines without too many missing pixels and segments?

Upvotes: 3

Views: 1616

Answers (2)

nathancy
nathancy

Reputation: 46600

If you want to isolate just black lines, a simple Otsu's threshold and bitwise-and should do it

enter image description here

import cv2

image = cv2.imread('3.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
result = cv2.bitwise_and(image,image,mask=thresh)
result[thresh==0] = (255,255,255)

cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()

Upvotes: 2

CypherX
CypherX

Reputation: 7353

This looks like a problem of signal-separation/processing.

I don't know if this would work or not. But this is just a hunch. Give it a shot and see if it works. Assume your image as a convolved image of the measuring strip and the ECG. So, if you process this in the Fourier domain, perhaps you could dis-entangle these two types of signals.

  1. Take fourier transform (FFT) of the image. (scipy has fft functionality). Call the original image: f and fft-image: F.
  2. Take an image of just the measuring strip (but no measured pattern on it for ECG) and evaluate the FFT for this one as well. Call this image: g, fft-image: G.
  3. Calculate inverse FFT of (F/G) and see if that clears up the background effect.

In case this does not work, please leave a note in the comment section.

Upvotes: 0

Related Questions