A Matlab function to digitize graphs (only the area defined by positive x-axis and positive y-axis) from images. Tested with Matlab R2017a.
The function expects one parameter, a path indicating where the image is located. The image should be
- in a common image format (jpg, png, gif, etc.)
- oriented such that positive x-axis is the lowest line, and positive y-axis is the leftmost line (as you'd normally view a graph)
Shortly, the function
- does a Hough transform
- finds the longest lines
- assumes the line with smallest y-coordinate (of center of mass) is the positive x-axis, and
- the line with smallest x-coordinate (and nearly at right angle against positive x-axis) is the positive y-axis
- finds the origo (intersection of abovementioned lines)
- finds the points inside the square defined by positive x- and y-axes
- transforms them from image's coordinate frame into the graph's coordinate frame
- does spline interpolation
The input image
The outputs
The algorithm is not particularly robust: it is based on some heuristics, and is sensitive to parameter tuning.