Tuesday, August 30, 2016

Close enough



The goal of this activity is to extract a hand-drawn (or X-Y plotter) graph from an "ancient" journal.
From the scanned image, the graph equation will be estimated to be used in reconstructing the graph numerically.

For this activity I used a plot from Dr. Caesar Saloma's 1986 Ph.D. dissertation paper.
Fig 1. Original scan
I rotated the image in GIMP, taking advantage of the guide tools to make sure that the x- and y- axes are as horizontal and vertical as possible.

From the extracted graph i randomly picked several points (got 82). Instead of manually noting down the pixel coordinates of the selected points, i drew over them on a separate layer. I loaded the new image in Python, converted it into a matrix and saved the pixel coordinates from that.
Fig 2. Extracting data points

From the extracted points, I used numpy polyfit to obtain an equation of the curve. Why polyfit? Because I have no idea what form the equation might be like and polynomial fitting is like cheating when estimating equations. It doesn't fit? Just add more terms. EZ GAME.

 Fig 3. First result using 5th degree polynomial

At first I did not know how to deal with the logarithmic y-axis so I left it as is. The scaling of the x-axis turned out to be pretty good where 155 x-pixels = 1 micrometer. I observed that a 5th order polynomial looks close enough and is actually better than having a 6th term.

After 2 hours of manually adjusting my parameters, I finally got a decent looking semilog reconstruction.
Fig 4. Final reconstruction using 10th degree polynomial.

I actually used a 10-term polynomial to fit this which I feel is way beyond cheating. I really have no idea how to deal with logscale axes. 
What I did:
  1. normalized y.
  2. converted y to magnitudes via y = 10^(ypix/ky);  where ky is the number of ypixels between 1 magnitude. I used 130 pixels.
  3. renormalized the converted values.
  4. multiplied by 12 (because i think the highest value is around 12 -- definitely above 10)
  5. subtracted a constant value such that the lowest value is 0.25 (which i think is the start of the x axis) 
It's really hard to estimate values in log scale. Problem here is that I dont have a nice equation for the curve. 10^(ay^10+by^9...+k) is just not legit.
Welp close enough.


Tools used:
  1. GIMP for image conditioning(?)
  2. Python 2.7 with scipy.ndimage and numpy
  3. Microsoft Excel for plotting
  4. Garena Plus Messenger -- my favorite screen shot tool that lets you highlight/draw on the spot (plus most of my friends that I want to talk to are online here. Who needs facebook.)
The screenshot interface looks like dis
 
Sige advertise pa.

Pabonus:

Fig 5. To overlay (backgroundlay? derp) image in Excel 
Nuff said.

Self evaluation
  1. Technical correctness    -    4    (close enough but dem logscale)
  2. Quality of presentation  -    3    (It's 5:40 and I still have to blog activity 3. Goodluck)
  3. Inititative                       -    1     (Bonus pls)
  4. Total                               -    8

 

No comments:

Post a Comment