If A Picture Paints A Thousand Words

And so begins the words of the a song by the Bread. The complexity we see in the world is a product of the interactions of simple building blocks. Everything we see is just a combination of a few elements in the periodic table. In turn every element is a combination of electrons, protons and neutrons.

A picture paints a thousands words but what paints a thousand pictures? Just like a Lego truck that is composed of a few Lego shapes, a “black and white” picture is also composed of a few levels of gray. The levels is just a set of 256 numbers starting from 0 up to 255. The number 0 represents black and the number 255 represents white. The numbers in between represent colors between extreme black and extreme white. The diagram below shows the levels of gray in a 16 by 16 matrix. The gradient goes from left to right, top to bottom.



Using just these 256 numbers, we can already draw interesting figures. Take for example this 8 by 8 matrix of numbers:

197   4  46  18 155 186 144 190 
111  30   6 131 235  99 112 227  
10   26 141 147 120  28  92 187 
241 100 118 149 178   5 158 213 
105  43 104  63 172 222  64 174 
130 194 243  56  59 166 134 133 
247 145  36  82 238 251  53 129 
171  29  51 163 199 214 113 195

When you plot this on an 8×8 grid, you get the following pattern:



Not all pictures need to be boring. Here’s an example of a picture that is not that boring:

17 23 26 20 13 20 20 22 21 17 17 25 20 11 15 15 9 10 18 13 14 12 13 39 61 63 71 72 69 71 74 72 74 75 72 76 75 75 75 80 77 78 79 79 80 80 80 80 81 81 82 82 83 83 83 83 84 84 84 84 85 86 86 86 87 87 87 88 88 88 89 89 89 89 90 90 90 90 90 91 90 90 91 91 92 92 92 92 94 94 95 95 95 95 95 95 96 96 96 96 97 97 97 97 98 98 98 99 99 99 100 100 101 101 101 101 102 102 103 103 104 104 104 105 105 105 105 105 106 106 106 107 107 108 108 108 110 110 110 110 111 111 112 112 113 113 113 114 114 115 115 115 116 116 117 117 117 118 118 119 119 119 120 120 121 121 122 122 123 124 124 125 125 125 126 127 127 127 128 128 129 129 129 129 131 131 132 132 133 134 ...

That is just the start of a 310×204 matrix saved in the file “clifton.txt”. If you plot that using the R command

clifton = read.table("clifton.txt")

#convert this data frame to a vector
vclifton = as.numeric(clifton) 

#create the 310x204 matrix
mclifton = matrix(vclifton,nrow=310,ncol=204)

#plot the image
image(mclifton[,ncol(mclifton):1],col=gray((0:255)/255))

you’ll get the following image



Histogram

If you look at the file “clifton.txt” and count the occurrence of each number, you will see that there are 9 occurrences of zero and 4 occurrences of 240. If you do this for all other numbers, you will get the following counts:

Level Frequency
0     9
1     16
2     31
3     34
4     49
:
:
237   115
238   113
239   18
240   4
:
:
254   0
255   0

If you plot this data as a bar chart, you will get what is known as the histogram of the picture:



The histogram above was obtained using the following R command:

hist(vclifton,breaks=256)

The histogram tells us the how much of each gray level contribute to the actual image.

Here’s another example of a picture that is relatively dark. In photography, the image below is called a “Low Key” image because it is mostly dark.



Low Key images tend to have the bulk of the colors at the right side of the scale. The next image is a “High Key” image because it is mostly white:

Histograms of High Key images tend to have the bulk of the colors at the right side of the scale. The histogram of the “clifton.txt” image tends to have a much better balance in that it contains most of the colors at the middle of the range.

It’s surprising how we can come up with complex images using just 256 levels of gray. We haven’t even considered colors yet! We also learned how histograms can be constructed by counting the frequency of each level and what histograms of High Key, Low Key and Optimum exposure look like.

A Sound Correction

As I was taking my coffee over breakfast today, I realized that in the previous post, I did not incorporate the time it took for the sound waves to reach my ear when I pressed the stop button of the stopwatch. Sound waves travel at 340.29 meters per second. At a height of 25 meters, it would take 0.073 seconds for the sound of the explosion to reach the ground. This should be negligible for the purposes of our computation. However, what is really the effect if we incorporate this minor correction?

As seen in the figure below, the recorded time is composed of the time it took for the skyrocket to reach the maximum height plus the time it took for the sound waves to reach my ear, that is,

t_r = t_a + t_s

where t_r is the recorded time, t_a is the actual time the skyrocket reached its maximum height and t_s is the time it took for the sound waves to travel from the maximum height to the ground.



We can rewrite the height as

\displaystyle h_{\text{max}} = - \frac{gt_a^2}{2} + v_i t_a

Since v_i = gt_a,

\displaystyle h_{\text{max}} =  - \frac{gt_a^2}{2} + gt_a^2
\displaystyle  =  \frac{gt_a^2}{2}

At the maximum height, h_{\text{max}}, it would take the sound waves t_s seconds to travel, that is,

\displaystyle h_{\text{max}} = v_s t_s

where v_s is the speed of sound. Therefore,

\displaystyle t_sv_s = \frac{gt_a^2}{2}
\displaystyle (t_r- t_a)v_s = \frac{gt_a^2}{2}
\displaystyle v_st_r - v_st_a = \frac{gt_a^2}{2}
\displaystyle \frac{gt_a^2}{2} + v_st_a - v_st_r = 0

The last equation above is a quadratic equation which we can solve for t_a using the quadratic formula:

\displaystyle t_a = \frac{-v_s \pm \sqrt{v_s^2 - 4(1/2)gv_st_r}}{2(1/2)g}

Substituting the values g = 9.8, v_s=340.29, and t_r = 2.3, we get

\displaystyle t_a = 2.22

Using this result, the maximum height is computed to be

\displaystyle h_{\text{max}} = \frac{gt_a^2}{2} = 24.33

Comparing this with our previous computation of h_{\text{max}} = 25.829, we find that we have overestimated the maximum height by about 1.49 meters. It’s not really that bad so we can just drop the effect of sound.

New Year, New Heights and the Projectile

I spent my new year celebration at our friend’s place with 2 other colleagues. It was started with a dinner at about 9:30 pm and we bought some bottles of wine in addition to the spirits we already brought. At about 10:30, a street party was setup in the vicinity and about 5 other families joined in a potluck. Marijo’s brother started the fireworks at about that time with David and Gerard (my colleagues) taking turns setting them off. I did not attempt to set them off because I did a lot those things way back as a child and still lucky enough to have my fingers intact.

This is a video of our 2012 New Year’s Celebration:

As Gerard was flying off skyrockets (or kwitis as they are called in my language) David asked me “How high do you think these things go up?”. That was a really good question which got me to thinking. I said “Let’s compute!” So I took my iphone and launched its built-in stopwatch. Gerard flew about 3 skyrockets and I took the time it takes for them to fly until they blow up in the air. The average was found to be 2.3 seconds.

Independent of Mass

Legend has it that Galileo Galilei performed an experiment at the Leaning Tower of Pisa. He dropped objects of different masses to see which of them falls first. Starting from the heaviest to the lightest object, what he found was that, in a vacuum, they reach the ground at the same length of time when dropped from the same height. Using this result, we can compute for the distance travelled by any object under the influence of gravity. At heights near the earth’s surface, the acceleration of objects in the presence of gravity alone is given by

\displaystyle \frac{d^2h}{dt^2}= \frac{dv}{dt} = -g

where h is the vertical distance (height), v is the velocity and g is the acceleration due to gravity given by g = 9.8 \text{m/s}^2.

The equation above is a simple differential equation which we can solve for the velocity at any time t by integrating both sides:

\displaystyle  \int^{v}_{v_i} dv = \int^{t}_{t_i} -g dt

which by the Fundamental Theorem of Calculus gives us

\displaystyle v - v_i = -g(t - t_i)
\displaystyle v = -gt + v_i + t_i

If we take initial time of the rocket launch to be zero, that is, t_i=0, we have

\displaystyle v = \frac{dh}{dt}=  -gt + v_i

We don’t know the initial velocity v_i of the rocket. However, at the maximum height attained by the rocket, the velocity is zero. Using this fact, we can solve for the initial velocity:

\displaystyle 0 = -gt_{\text{max}} + v_i
\displaystyle v_i = gt_{\text{max}}

where t_{\text{max}} is the time the rocket reached maximum height.

At t_{\text{max}}=2.3 seconds, the initial velocity is therefore v_i = 9.8 * 2.3 = 22.5 m/s.

Maximum height

We can solve for the height as a function of time by integrating both sides of the velocity equation:

\displaystyle \int^{h}_{h_i} dh = \int^{t}_{t_i} -gt dt  + v_i dt
\displaystyle h - h_i = -\frac{gt^2}{2} + v_i t \big|^t_{t_i}

Since the initial height is zero , that is , h_i = 0 and the initial time is zero t_i = 0, we have

\displaystyle h = -\frac{gt^2}{2} + v_i t

Since at t=2.3 seconds, the rocket reaches the maximum height, we have

\displaystyle h_{\text{max}} = -\frac{9.8 \times (2.3)^2}{2} + 22.5 * 2.3 = 25.829 \text{ meters}

Does this make sense? The average height of a building storey is about 3 meters. This is about 8 or 9 storeys high which I think makes sense.

It’s good that my new year not only started with a warm welcome from friends but it also appealed to my physics curiosity.

Thank you to Marijo Condes and family for letting us spend a memorable New Year’s Eve.