This isn't always easy but can possibly be done, depending on the graph. Here's one way to do this for the graph you've provided. There may be more efficient ways out there, as I've no background in image processing--apologies.
The idea is to get the pixel values for the image, and focus on differences between the background and the graph. In this case, the graph color was the minimum in any column of pixels. In other cases, you may need to derive some sort of bandpass filter, etc. For a multicolored background, even this approach might not work, if the color of the graph were the same as one of the colors in the background. At any rate, try this out.
This is a crude approach but should give you a starting point. Cleaning up/smoothing the data is not that hard to do after the fact. I'm sure others will find many ways to improve on the approach and performance, as well.
NOTE: I did not rescale x and y. Again, that is not hard to do once you've got the matrix down to the graph's data.
I have attached the .png I used so you can use the same file I did.
Cheers,
Brady
Names Default To Here( 1 );
//need to save image and put the file path in the open() function.
New Window( "Example", pb = Picture Box( Open( "/Users/brady.brady@jmp.com/Downloads/graphPic.png", png ) ) );
img = pb << get image;
pixMat = img << get pixels;
pixMat = 1000*(floor(pixMat/1000)); //smooths values; use whatever factor you like
dt = astable(pixmat);
eval(substitute (
expr(dt << new column("Row", formula( _ROW_ - :row()))), //low rows for pixels are high. This is a fix for that.
expr(_ROW_),
nrow(dt)
));
dt:row << Delete Formula;
dt << move selected columns({"Row"}, to first);
dt << select where (:row() <= 20 | :row() >= 265) << Delete Rows; // top and bottom few rows of this table are not useful
stackCols = (dt << get column names)[14::ncol(dt)];
dtStack = dt << Stack(
columns( stackCols ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
"Non-stacked columns"n( Keep( :Row ) )
);
dtStack << select where (:data == col minimum(:data, :label)); //in this case, minimum color is the graph.
dtSub = dtStack << subset(selected rows(1), selected columns (0));
dtSub << new column("x", formula(num(substitute(:label, "Col", ""))));
summarize(dtSub, b = by(:label), yVals = mean(:Row), xVals = mean(:x));
astable(xvals || yvals, <<column names({"x", "y"}));
Graph Builder(
Size( 982, 232 ),
Show Control Panel( 0 ),
Variables( X( :x ), Y( :y ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch(
{},
"x",
ScaleBox,
{Format( "Best", 12 ), Min( 6.17686033877992 ), Max( 953.120680816302 ),
Inc( 200 ), Minor Ticks( 1 )}
)
)
);
//now just need to scale x and y