Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting graph from printed ecg

I found one question like this on stack but it was not answered, plus my image is different.

I have this image that you see below.

enter image description here

I want to extract the graph that is on the image. I have tried very many ways to extract it. Thresholding does not seem to work as rgb values are pretty close, especially at the peak of the graphs. I have tried using gradients to detect the flow on the image, but it also failed. I tried combining different color spaces (HLS, YUV, LAB) it had some output, but it was removing some parts of graph. I also tried creating mask matrix 8X8 or smaller, to get average pixel value and remove everything below that. Also creating median filtering. Those last two combined with some of the before mentioned techniques helped, but they were removing peaks, as there is the lowest difference. Do you know any better ways that can help me?

Note: I use Python

like image 442
MadLordDev Avatar asked May 18 '18 11:05

MadLordDev


1 Answers

U could play around with thresholding your image (HSV)

import cv2
import numpy as np
from PIL import Image
import PIL.ImageOps   

img=cv2.imread("ekg.jpg")
BLACK_MIN = np.array([0, 0, 0],np.uint8)
BLACK_MAX = np.array([255, 255, 80],np.uint8)
hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
frame_threshed = cv2.inRange(hsv_img, BLACK_MIN, BLACK_MAX)
cv2.imwrite('threshed.jpg', frame_threshed)
image = Image.open('threshed.jpg')
inverted_image = PIL.ImageOps.invert(image)
inverted_image.save('invert.jpg')
img2=cv2.imread("invert.jpg")
cv2.imshow('image1', img2)

enter image description here

like image 178
kavko Avatar answered Nov 12 '22 02:11

kavko