Extract Graph Data from image

this isn’t trivial.

all the variation you get from random users using random smartphones taking random photos of random ECG plots…

some thoughts…

  • rectify the snapshot so the plot becomes a real rectangular frontal view
    – look for “opencv document scanner”, replicating a “camera document scanner” is reasonably simple, unless your picture doesn’t lend itself to the simple approaches
  • remove grid lines/dots
    – could be done with a fourier transform, masking the right high frequency components, and transforming back. or maybe not. depends on what you have to deal with.
  • depending on picture quality, remove vignette and other coarse shading effects
  • maybe threshold, can’t say without dealing with a bunch of examples
  • don’t use findcontours, that’s drawing a line around blobs, but your blobs are the lines themselves.
  • split the picture into its subplots, treat each individually
  • I’d walk pixel column by pixel column, get centroid/mean/mode/median/… and that shall be the y-coordinate at that pixel column