Sunday, 8 March 2015

How do I recover the signal from an ECG image


In my project, I have to digitize an ECG image taken with a normal camera (jpeg). For example, I have the following camera captured image:


Before


and I want to get something like this:-


After



and then the digitized data (x,y points), like in this video on digitization of ECG


I have no idea how to do it, so I searched and consulted several research papers. The general approach of the algorithms is like:-



  1. change to gray level image

  2. delete gridlines

  3. add missing points

  4. convert 2D image to 1D image


I am stuck with the second point, i.e., deleting the gridlines. I looked up some more references to do this and found histogram analysis might be helpful.


Can you please guide me on how to do this (I'm using MATLAB 2010)? Any help would be appreciated.




Answer



Sorry, I use Mathematica, but it should be really easy to implement the idea into Matlab. I give the code anyway, so when my description is not detailed enough, you can get the rest from the code.


Basic idea is: you look at your image column-wise. Process every column of pixels separately. Note, that in the plot, I inverted the gray-values. So black is 1 and white is 0.
If you plot the (inverted) brightness-pixel-values you have basically only two situations. The first one is, when your column is not on a vertical grid line. The the plot looks like



The second situation is, where you are directly on a vertical grid line. Then the grid line influences the brightness of the whole column



But what you see is, that your dark EEG seems to be always the maximum. Therefore, the very complex algorithm is: Go through every column and take the position of the most black pixel.


img = ColorConvert[
ImagePad[

Import["http://i.stack.imgur.com/500Kg.jpg"], {{0, -20}, {0, 0}}],
"Grayscale"];

Image[
Transpose[Function[With[{m = Min[#]},
Map[Function[{v}, If[v == m, 1, 0]], #]]] /@
Transpose[ImageData[img, "Real"]]
]
]


Note, that I croped a bit of the right side of you image, since it was completely white there. The result is



Now you can join the points or interpolate them in every way you like and you get your EEG



No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...