I'm a little confused as to whether your problem is simply determining the color of the pixels in the image or if the problem is the math of what you are trying to do.
For the first, do the following:
BufferedImage bimg = ImageIO.read(new File("whatever.png")); // get the colour of the pixel at position (x, y) int col = bimg.getRGB(x, y); // decode red, green and blue components of colour if necessary int r = (col >> 16) & 0xff; int g = (col >> 8) & 0xff; int b = col & 0xff;
If on a chart you just want to return a data set (i.e. do not get an equation from this data), then you essentially iterate over each X position and find the Y position, where there is a color pixel that the chart draws the program uses. If the graph has axes, smoothing, etc., then the task will be more difficult.
The task of obtaining an equation from the data is potentially much more complicated, but you can start by checking some suspicious formulas, such as y = mx + c, as you mentioned. For example, you can check the difference between each Y position for the last; if this difference is always the same, then you have a straight line graph (and at this point the derivation of the formula should be trivial).
For testing other equations, this helps to find out a little calculus. Then the starting point is to see if the differences in the differences of the derivative correspond to the equation in question. (As an example, if the equation y = ax ^ 2 + c, then with each increase in X, the increase in Y will itself increase by 2a.)
source share