Friday, August 26, 2016

Activity 2 - Digital scanning

Activities 2 and 3 were given last August 17, but I was not able to attend class that time since we travelled to Iloilo that day to attend the SPP Conference scheduled August 18-21 (apologies, ma'am). I was only able to start the activities last August 24. Good thing the activities were scheduled for 3 meetings. Since ma'am was not able to attend class, I opted to work on the activities independently in our lab.

Activity 2 of AP 186 is about using ratio and proportion to determine the values of points on a scanned plot, relating the the number of pixels on the image and the values of the variables on the plot.

First thing was to scan a plot, either hand-drawn or plotted using an XY plotter. I am fortunate that our lab has a flatbed scanner (HP Scanjet G2410) that I can use for this activity. I used Dr. Sarmago's PhD dissertation (thank you sir!) as my source of a plot, which is shown below.

Scanned copy of a plot in Dr. Sarmago's PhD dissertation. 
After scanning the plot, the image was opened in MS Paint, and the positions of the tick marks in terms of pixels were noted and recorded, along with the corresponding values of the variables. The values are tabulated in a spreadsheet and are shown below.

Tabulated values of the pixel positions of tick marks and the equivalent pixel distance for both axis tick intervals
The distance between tick marks in terms of pixels were calculated for each adjacent tick mark, and these values were averaged for each axis. The calculated averages correspond to the distance in pixels equivalent to the intervals of the tick marks. It was calculated that there are 75.2 pixels per 0.3 Nd concentration, and -24.2 pixels per 10 K. Note that these will be measured from the point (0,0) (in terms of the physical variables). The ratio for the x axis is positive because the pixel position increases from left to right. The ratio for the y-axis is negative because the pixel position decreases from bottom to top. 

The scanned graph was then reconstructed using the calculated ratios. The pixel positions of the points on the graph were then tabulated (pointer was positioned at the center of the points). The pixel distances from the origin were calculated, and by ratio and proportion (multiply pixel distance along x by 0.3/75.2, and the pixel distance along y by 10/-24.2), the values of the variables were calculated. These values were then plotted using SigmaPlot, also noting to scale the point where the vertical and horizontal axes meet. I opted for SigmaPlot since I cannot figure out in MS Excel how to cross the axes at the calculated point at the same time retaining the tick intervals. This was easy to do in SigmaPlot but somehow I could not do it in MS Excel. The reconstructed plot is shown below.

Reconstructed plot of the scanned graph showing Tc,zero vs Xs

In SigmaPlot, it is not possible to replace the background of the plot by an image (only solid colors were available). So I overlayed the scanned image and the reconstructed plot using MS Powerpoint, coinciding the lower left corners of the plots (However, I know how to overlay images in an Excel plot, which I will discuss in the latter part for the bonus points :) ). The overlayed images are shown below. 
Image of the overlayed scanned and reconstructed plots

The ticks (especially the left and bottom axes) and the points of both graphs more of less coincide; however, the axes do not. I was able to observe from the calibration part that the axes of the scanned graph were angularly displaced by slightly less than 90 degrees. When I tried going from the lower left corner of the plot and up (keeping the same x pixel), the axis was off towards the right. On the other hand, when I tried going from the lower left corner of the plot and to the right (keeping the same y pixel), the axis was off upwards. This may have contributed to the errors in the interpolation of the points' values and the observable deviations of the tick marks in the right and top axes). Of course we also consider the errors brought about by the finite resolution of the scanned image. With these in mind, maybe I'll give myself a rating of 9.


Overlaying an image on the background of an MS Excel graph

This is quite easy to do (as I've learned from http://www.mrexcel.com/forum/excel-questions/19950-inserting-image-behind-excel-graph.html). This can be done by right clicking on the chart, and click Format Chart Area. Under Fill, there's an option to use a Picture or texture fill. From here, we can choose an image to be used as a background of the chart. We should be careful that the background of the plot are should be transparent or have no fill. A sample overlay is shown below.

Sample overlay of an image on the background of an MS Excel graph


Thanks to the CMPL Supercon lab for having the resources that I needed for this activity. 

Activity 3 - Scilab Basics

Similar to activity 2, I was able start with activity 3 last August 24 for the same reasons. Since ma'am was no able to attend class that time, I chose to work on the activities in our laboratory and work on it independently.

Activity 3 involves the use of Scilab, which is a very powerful programming language advantageous for matrix calculations. The activity serves as an introduction to Scilab employing some of its basic commands, which shall be vital since the activities will become more avanced as the semester progresses. 

In this activity, we were tasked to synthesize images using Scilab. Images are represented as matrices so we exploit the capabilities of Scilab to do this. A sample code was given which produces a centered circular aperture as shown below.
Centered circular aperture
The sample code was very helpful in serving as a basis on how to produce the listed target images, which were: centered square aperture, sinusoid along the x (corrogated roof-like pattern), grating along the x, annulus, circular aperture with a Gaussian transparency, cross, and an ellipse. Of course, as most of the time, I also seeked help from a very good friend -- Google. I searched for some of the commands and syntax of Scilab, which mostly led me to the help.scilab.org website. The synthesized images are shown below
Centered square aperture
Sinusoid along the x-axis (corrogated roof-like pattern)
Grating along the x-axis
Annulus
Circular aperture with a Gaussian transparency
Cross
Ellipse
I also tried applying the basic matrix operations to the different matrices corresponding to the images above. These includes addition (+), subtraction (-), multiplication (*), element-wise multiplications (.*). The resulting images are shown below.
Centerd circular aperture + centered square aperture
Circular aperture with Gaussian transparency - annulus
Annulus * centered circular aperture
Sinusoid along the x-acis .* grating along the x-axis
 It is interesting to note that when addition, subtraction, and element-wise multiplication were performed, the resulting images still showcased the general apperance of its constituents. Take for example the image when both the centered circular and square apertures were added. We can still see a circular and square pattern in the image. The same goes for annulus * centered circular aperture and sinusoid along the x-axis .* grating along the x-axis. On the other hand, when matrix multiplication was performed, the resulting image was entirely different from the multiplied matrices. Circular profiles, which are the main features of the constituents, are not observable in the resulting image.

Aside from the prescribed images to be synthesized, I also synthesized an image of a pokeball, inspired by the currently trending game Pokemon Go. At first, I thought that the synthesis of this image would be difficult. But due to the symmetry of the image and the similarity of the patterns to the images above, I was able to produce the image as shown below. 
Pokeball
The activity was fun yet very helpful. Having used Scilab last semester just briefly, this activity has helped me to review what I already know about Scilab, learn new things about the language, and further engrave in my mind the things-to-know about Scilab. I am excited about further lessons involving the use of Scilab in a more advanced topic. For this activity, maybe I will give my self a grade of 11. I was able to produce all the listed target images, along with other images employing matrix operations and, in addition, a pokeball. I think that the images are also presented well.

I have included the code which produced the images above, for the reference of those who want to produce such or similar patterns. 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
nx = 100 ; ny = 100 ;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);

// Centered circular aperture
r = sqrt(X.^2 + Y.^2);
A = zeros(nx,ny);
A(find(r<0.7)) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

// Centered square aperture
B = zeros(nx,ny);
B((nx/2)-(nx/4):(nx/2)+(nx/4), (ny/2)-(ny/4):(ny/2)+(ny/4))=1;
f2 = scf();
grayplot(x,y,B);
f2.color_map = graycolormap(32);

// Sinusoid along the x-direction
C = sin(30*X);
f3 = scf();
grayplot(x,y,C);
f3.color_map = graycolormap(32);

// Grating along the x-direction
D = zeros(nx,ny);
D(:,1:5:100) = 1;
f4 = scf();
grayplot(x,y,D);
f4.color_map = graycolormap(32);

// Annulus
r1 = sqrt(X.^2 + Y.^2);
E = zeros(nx,ny);
E(find(r1>0.3 & r1<0.7)) = 1;
f5 = scf();
grayplot(x,y,E);
f5.color_map = graycolormap(32);

// Circular aperture with Gaussian transparency
r3 = sqrt(X.^2 + Y.^2);
F1 = zeros(nx,ny);
F1(find(r<0.7))=1 ;
F2 = exp(-(X.^2 + Y.^2)/0.05);
F = F1.*F2;
f6 = scf();
grayplot(x,y,F);
f6.color_map = graycolormap(32);

// Ellipse
a = max(x)/2; b = max(y)/4 ;
r4 = (X.^2 / a^2) + (Y.^2 / b^2);
G = zeros(nx,ny);
G(find(r4<1)) = 1;
f7 = scf();
grayplot(x,y,G);
f7.color_map = graycolormap(32);

// Cross
H = zeros(nx,ny);
H((nx/2)-(nx/4):(nx/2)+(nx/4),(ny/2)-(ny/8):(ny/2)+(ny/8)) = 1;
H((nx/2)-(nx/8):(nx/2)+(nx/8),(ny/2)-(ny/4):(ny/2)+(ny/4)) = 1;
f8 = scf();
grayplot(x,y,H);
f8.color_map = graycolormap(32);

// Circular aperture + square aperture
f9 = scf();
grayplot(x,y,A+B);
f9.color_map = graycolormap(32);

// Sinusoid along the x direction .* grating along the x
f10 = scf();
grayplot(x,y,C.*D);
f10.color_map = graycolormap(32);

// Annulus * circular aperture
f11 = scf();
grayplot(x,y,E*A);
f11.color_map = graycolormap(32);

// Pokeball
r5 = sqrt(X.^2 + Y.^2);
P = zeros(nx,ny);
P(find(r<0.2))=1;
P(find(r>0.3 & r<0.8))=1;
P(:,48:53) = 0;
P(find(r<0.2))=1;
P(find(r>0.1 & r<0.13))=0;
f12 = scf();
grayplot(x,y,P);
f12.color_map = graycolormap(32);