I am working on an idea wherein I have to identify lines in a JPG or PNG file. The PNG file contains one graph of a single value – one x,y combination. For example, the graph looks like Y = mx+c. I would like to identify the line in the graph – if I can indentify the position of the pixel in the frame, I believe I can get back the values (x,y) which were used to plot the graph. The assumptions here is – I know the scale i.e 1 pixel = what unit of Y ? Can somebody please help me to write a code which will identify the pixels of a specific color in one PNG file?
EDIT
Lets take an example to make it clear. Lets say I have a set of data values X and Y like this –
X = 1, Y = 10 X = 2, Y = 20 X = 3, Y = 30 X = 4, Y = 40 X = 5, Y = 50 X = 6, Y = 60
In this case, if I use jfreechart type of charting tool and make a chart, it tools like a straight line.
So the input is the dataset and output is the .PNG file (using jchart or jfreechart) containing this line graph for Y values.
Question is – if we reverse the flow, can we develop one program which will take the PNG file (that contains the graph) and give me back the dataset.
The context of the problem is — I want to store the PNG files in my application and not the raw dataset. But given a PNG file, I should be able to get back my dataset.
I’m a bit confused as to whether your problem is simply determining the colour of pixels in an image, or if the problem is the mathematics of what you’re trying to do.
For the former, do something such as the following:
If from the graph you just want to get back the dataset (i.e. not derive an equation from that data), then you essentially loop through each X position and find the Y position where there’s a pixel of the colour that the graph plotting program uses. If the graph has axes, antialiasing etc, then the task will be more complex.
The task of deriving an equation from the data is potentially much more complex, but you can start by checking for certain suspected formulae such as y = mx + c as you mention. For example, you can loop through checking the difference between each Y position for the last; if that difference is always the same, then you’ve got a straight line graph (and at that point, deriving the formula should be trivial).
For testing for other equations, it helps to know a bit of calculus. Then, a starting point is to see if the differences in the differences match the derivative for the equation in question. (Just as an example, if the equation is y = ax^2 + c, then for every increase in X, the increase in Y will itself increase by 2a.)