Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Reconstruction of Charts from Images

Rate me:
Please Sign up or sign in to vote.
4.92/5 (13 votes)
18 Mar 2010CPOL7 min read 37.9K   4.1K   42   4
Usage of universal framework for chart reconstruction
Image 1

1. Introduction

The universal framework for science and engineering is devoted to the development of Grandiose Projects. So it is not easy to catch it. Here I provide a simple typical sample of framework application. I hope that this sample will provide a better understanding of the Framework. Let us describe the sample. Suppose that we have a bitmap image of chart (See picture above). We would like to obtain numeric information from this chart. Moreover we would like to obtain math dependency from this chart. The bottom part of the above image contains digital information and approximation of it by polynomial.

2. Background

Reconstruction of charts from image is briefly considered in my article Digital Image Processing. However my friends asked me for more details and particular cases. Reconstruction with marking is considered in this article. Suppose we have image with the following chart:

Image 2

The following text explains step by step reconstruction of the image.

2.1 Filtering

We can construct digital filter for obtaining its points. This filter would require a lot of intellectual work. It would be easy to mark the image with colored points as it is presented below: 

Image 3

Origin of coordinates is marked by red color, top point is marked by green color, right point is marked by blue color. Points of chart are marked by aqua color. Then we use digital filters for definition of points. For example, filter of chart point is presented by the following expression:

Image 4

Where r, g and b are intensities of red, green and blue color respectively. Parameters x and y are threshold values for filter. After filtration, we have chart points that are marked by black points.

Image 5

Filtration algorithm is presented in the following picture:

Image 6

The Source object is source image. The Points Filter object contains necessary math operations. The Points Filter object represents the result of filtration. The filtration result is presented below: 

Points.gif

The Points Selection object transforms filtered image into digital selections. The first selection is a selection of X - coordinates of black points, the second one is a selection of Y - coordinates. So we already have digital representation of points of chart: 

Selection_of_Points.jpg

However the image should be scaled. Moreover the image can have skewing. The calibration is needed.

2.2 Calibration

Shift, scale and skew of image can be compensated by following expression:

Image 9

where xphysical is physical 2D vector which corresponds to physical coordinates x and y. ximage coordinates of this point in image. Vectors a, b define shift of image and matrix M defines scaling and skewing. Definition of these parameters contains definition of coordinates of image points and math processing. These operations are considered below.

2.2.1 Definition of coordinates of points on image

Definition of coordinates of base points is presented by the following sample:

Image 10

The Source object is the source image. The Zero Filter object contains filtration expressions of the image. The result of filtration is the Zero Image object. Result of filtration is the image with a single black pixel. We would like to define its coordinates. First of all, we transform this image to selections using Zero Selection component. This component transforms image into two selections. The first selection is the selection of X coordinates of black pixels. The second selection is the selection of Y coordinates of black pixels. The Zero Processor object performs definition of coordinates. Properties of this object are presented below: 

PointRegression.jpg

This component defines parameters a and b of Zero Regression. It compares Formula_1 and Formula_2 of Zero Regression object with X and Y selections of Zero Selection object. In result parameters a and b of Zero Regression are estimates of X and Y coordinates of pixel which corresponds to origin of coordinates. Similarly top and right point is being defined.

2.2.2 Math processing

The full picture of math processing is presented in the following picture:

ResultPoints.jpg

Let us describe its components. The Scale object enables us to manually define physical values of border values of coordinates. Properties of this object are presented below:

Scale.jpg

where a=xmin, b=xmax, c=ymin, d=ymax. This data set and data obtained in 2.2.1 is quite enough for definition of vectors a, b define shift of image and matrix M. A set of squares contains necessary formulas. Using the above transformation, we can define physical values of chart point. The following picture contains chart and digital representation of these points:

Calibrated_Points.jpg

2.3 Regression

So we have physical values of points. We would like to approximate them. We use regression for this purpose. I already wrote an article about regression. Here I will consider approximation of points by polynomial. The Regression 3 component is used for regression formula. Properties of this component are presented below:

Regression_component.jpg

Formula of this component is formula of polynomial of degree 3. The x is variable of this polynomial. Otherwise x is Formula_1 of ProcessedX project. Formula_1 calculates array of calibrated X coordinates of chart. Output of this formula is componentwise calculation of this polynomial. This component is used by Processor 3 component. Properties of this component are presented below:

Processor_component.jpg

These properties have the following meaning. Left pane means that parameters a, b, c, d of Regression 3 component should be defined. These parameters are polynomial coefficients. The 0 of middle and 0 right pane mean that Formula_1 of Regression 3 object should match to Y - selection of Scaled Points object. The (-1) means neglecting of formula or selection in regression component. So Processor 3 approximates ordinates of selection by polynomial. Approximation result is presented below:

Regression_result.JPG

Green curve is the result of interpolation by polynomial of degree 3. Red crosses are points of chart.

3. Automation Equipped Working Place for Image Reconstruction

The framework is too complicated. If the user would only like to reconstruct charts, then he does not need to learn complicated framework. So special application for such users is developed. The framework is used as computational resource. A screenshot of the application is presented below:

Image 18

User marks points of image and then user obtains digital information and approximation. Since application information is obtained by mouse events, we do not need digital image processing. Our algorithm uses coordinates of clicks. The new algorithm is presented in the following picture:

Image 19

This algorithm is very close to the algorithm described in part 2. But Points Selection is described in part 2 algorithm is selection obtained from image. In this Points Selection is apriori known selection.

This algorithm is saved to file ChartRestorationPure.cfa and is used as an application resource:

Image 20

Resource parameters are obtained from user interface. User mouse clicks the following form:

Image 21

In result pixels of chart become aqua. Similarly if we change selection of combobox...

Image 22

...then we can mark Top, Right and Origin point of chart image. Physical limits of X and Y user are entered to DataGridView.

Image 23

Then this data set is used in the following way:

C#
// Virtual desktop
desktop = new PureDesktopPeer();

// Load desktop from resource
desktop.Load(Properties.Resources.ChartRestorationPure);

// The "Points Selection" object. This object is series
DataPerformer.Series s = desktop.GetObject("Points Selection") as DataPerformer.Series;

// Clears series
s.Clear();

// Fills series by points obtained from points obtained from mouse clicks
foreach (int[] x in marks)
{
   s.AddXY((double)x[0], (double)x[1]);
}

// The "Scale" object. This object implements "IAlias" interface
IAlias sc = desktop.GetObject("Scale") as IAlias;

// Filling parameters of this object by values from DataGridView
sc["a"] = scale[0, 0];
sc["b"] = scale[0, 1];
sc["c"] = scale[1, 0];
sc["d"] = scale[1, 1];

// Objects which contains information about Origin, Top and Right point of chart image
string[] ss = new string[] { "Zero Regression", "Top Regression", "Right Regression" };
string[] ab = new string[] { "a", "b" };
for (int i = 0; i < ss.Length; i++)
{
   IAlias alias = desktop.GetObject(ss[i]) as IAlias;
   for (int j = 0; j < ab.Length; j++)
   {
      // Filling values by values obtained by mouse click
      alias[ab[j]] = (double)coord[i, j];
   }
}

So stored in resources virtual desktop used as computational resource. We have access to objects of virtual desktop and their properties. This application enables us approximate charts by polynomials. Approximation chart and cooeficients of polynomial are presented below:

Application_Chart.jpgApplication_General_Coefficients.jpg

Points of Interest

The way of understanding of framework is not easy. However the shortest way is not the best way. Difficulties should not stop my attempts. Moses used 40 years for training of his people. If explanation of my ideas requires even 40 years, then I should not stop my work.

History

Recently my friend asked me about chart reconstruction. I've answered that this problem is contained in my article devoted to digital image processing. He said that this article is very complicated. I find that chart reconstruction is a very popular theme and a good promotion of my ideas.

Prospects

If this article would be popular, I will improve my soft devoted to reconstruction of charts. The following webpage is devoted to chart reconstruction. These pages will contain different methods of filtration and regression. Polynomial approximation is the simplest method of regression.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions

 
Generalexecutable Pin
LOUIS Christian18-Mar-10 22:07
LOUIS Christian18-Mar-10 22:07 
GeneralRe: executable Pin
Petr Ivankov18-Mar-10 23:02
Petr Ivankov18-Mar-10 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.