Convert a raster chart to a data table
Such tasks sometimes arise. For example, more recently, I came across the data of a field experiment conducted 10 years ago. Those graphs that I need turned out to be in the form of ... ordinary raster * .bmp files. There were no tables with values among the material for the experiment. And the tables of values would be very useful, because these data must be compared with my modeling results, and then the whole thing should be done at the proper level.
This problem has occurred a couple of times in the past. For example, when I helped my beloved woman do coursework on electric machines - the calculations were done in Maple, and most of the calculated data were available in Kopylov’s textbook in the form of graphs. And this is also a raster. And a lot of blood was spoiled before the necessary tables were driven by us into the program.
In general, if a person has no problems, he comes up with them in order to successfully and heroically solve them. Having scratched my head and armed myself with Google, I began to look for a not-too-painful solution to the problem.
It is clear that the first stage - raster graphics must be turned into vector ones. And from the vector format, especially if it is open, numerical data can be pulled out, scaled and turned into a table.
The first thing I tried Inkscape. I use this editor very often - despite the fact that it was hard to start working with it, today it is the main tool for drawing various paintings for articles, reports and other scientific documentation.
However, automatic vectorization tools did not cope with the task, or rather they did, but not as much as we would like. It is possible that I did not fully understand them. In any case, attempts to use Inkscape were abandoned indefinitely and again turned to Google.
The answer was found ... on ENT! The answer was Easy Trace Pro . According to the authors, this program is an intelligent map data tracer, and is intended for vectorization of maps.
This program is proprietary software for OS Windows, however, together with the paid version 9, the authors propose a fully functional previous version - 7.99 for free download and unlimited use. In addition, the site has instructions for launching Easy Trace using wine. I did not try the last one - I launched a virtual machine with Windows and installed a free version.
The result exceeded my expectations. Perhaps the used equipment is another "bike", but it has borne fruit, and if you are interested in this too, I ask for a cut.
1. Statement of the problem
So, we have a raster chart. For a good example, one should take the graph for the experiment that caused the whole fuss. But (no need to throw a slipper at me) I will not publish it. The data was transferred to me for personal use, but no one gave permission to publish, and I did not ask. So to illustrate the solution to the problem, let's take my graph, after turning it into a raster one, for example, into the same PNG. PNG is taken to spare the time and nerves of my readers, to speed up the loading of pictures.
We install Easy Trace Pro and create a new project there based on the raster file. We set the
units and position of the origin - I took the millimeters and the lower left corner.
As a result, our project is ready
2. Tracing the line of the graph and converting to tabular format
Raster vectorization is a process that does not exclude manual labor. Moreover, there are several graphs here, my experiment data was also of such a plan. Therefore, the first thing we do is select the color by which the tracing will be done.
Tools -> Tracing -> Color Set
Use the mouse cursor to point to the desired chart and click on the desired color in the window near the cursor.
The mouse cursor didn’t work out on this screen - apparently shy, but the selected chart is visible on the next screen - it is highlighted in pink.
Now we will trace. I didn’t read the program manual, so I acted on the bummer, and I must say, the program is friendly enough for a new user
Tools -> Tracing -> Curved
After that, we click the cursor to the beginning of the graph
And the program draws a rather long line along the graph curve, choosing it from all the contents according to the color we set. And it stops only where it is not clear where to go next. You can see in the screenshot - I came across a high-frequency “daub”. This section will have to be carefully passed manually.
After we pass it, the trace will confidently rush on, as if walking along the curve of the graph
and will stop again. You will have to go all the way manually, but it is obvious that for fairly smooth curves, the process will go automatically without interference.
After we have gone through the entire chart, we have a vector curve that needs to be converted to a table of points.
File -> Export.
In the window that appears, select the format.
I must say that the choice is not great, and the only position that will interest us is CSV, which can be opened in Excel or LibreOffice Calc. Next, we configure the export options, in particular, select the vector layer in which our graph is located,
set the file name
and pay attention to the type of data column separator - a default comma will suit us.
Everything contains data taken from the raster in the graph.csv file graphics.
3. Translation of data into units of interest to us
Naturally, we are interested in X, Y not in millimeters from the lower left corner, but units of measurement, laid down along the axes. In addition, you need to adjust the position of the origin. We will do this in LibreOffice Calc, although you can use any other software suitable for processing data arrays.
Open the data table in LibreOffice Calc.
Here we pay attention to the encoding, we select the language “enemy” - so that the separator of the integer and fractional parts is a period. We import the table starting from the 4th row, ignoring the last two columns with zeros. Click OK and get the data table.
Now adjust the zero. To do this, we measure at what distance is zero from the bottom and left edges of the picture. From the left it’s obvious at 15.325 mm, since this is the first point of the graph. Subtract this value from all values of the first column.
The ordinate of the first point is also zero, which means 69.342 must be subtracted from the second column. But it is in this case. Otherwise, in Easy Trace there is a ruler with which you can determine the zero offset.
Done, zero is where you need it. Now let's calculate the scale along the axes. Measure with a ruler the time axis and the ordinate axis. It turns out this alignment: 20 seconds corresponds to 184.4 mm of the abscissa axis, and to 600 kilontons - 80.4 mm of the ordinate axis. In proportion, we adjust the values from column C and D of our table.
In general, cheers - we have a data table torn from a raster chart. It remains to verify how all this corresponds to the truth.
I have data for the initial graph from the example (I received it myself), so I’ll just build both graphs and we will compare them.
The coincidence is lame only in places where the graph line was smeared on the raster, but with proper dexterity it was possible to adjust it and better.
Nevertheless, we have a table of data that can be built into a vector, interpolated, and processed as we need.
The stated approach is quite ingenuous and accessible to everyone. I myself do it for the first time, at the first prompt that worked, so I can not navigate the technique of such work. If the reader can offer something more rational, then the author is open to constructive criticism.
Thank you for attention!
PS: Easy Trace Pro starts and runs fine under wine, so there is no need for virtual Windows