Here’s a simple (OK, as simple as possible) explanation of how light entering your digital camera lens turns into a photo in Photoshop, which you can manipulate. If computers and/or digital photography are a mystery to you, then give this explanation a try. I’ve done my best to keep all the “geek-speak” out of it.
A Bit of a Nibble of a Byte: the Word on RAM.
(or how electronic memory works: a guide to digital photography)
Ever wonder how the light that enters your camera lens is translated into an image? Well, here we go.. and along the way you’ll learn a lot about how computers work.
Don’t worry: there will be as little Geek-Speak as possible.
A computer is just a box of stuff that does amazing things; how do it do it?
Well, you’ll soon see that it’s very simple; what’s amazing is how fast it does very simple things.
A computer is basically a box full of switches. Simple On/Off switches, just like the light switch on your wall. Either the switch is on, or the switch is off. There’s no inbetween.
What’s different is -how- the switch is flipped. Your light switch takes a human being to actually flip it up or down.
An electronic switch does away with the need for a mechanical flipping of the switch: it uses a second bit of electricity. Think of it like this: suppose there was a motor connected to your light switch: turn the motor on, and it holds the switch in one position; turn the motor off, and the switch falls back to it’s previous position.
Well, that’s what a transistor is, but without the physical motor. If you apply a bit of electricity to the third “leg” of a transistor, and it allows current to flow along the other two legs. Take away that electricity on the third leg, and the circuit on the other two legs is opened, and it electricity stops flowing.
Yep: this means there are two different sources of electricity: the one that is attached to the third leg, and the other that is being controlled.
The cool thing about this is that the third leg needs only the very tiniest amount of electricity to close the circuit (flip the switch) between the other two legs, and the electricity there can be (and usually is) -much- larger.
OK: so there we have the basic: a transistor is just a switch that is turned on or off by a tiny amount of electricity. If the current is there, the switch is turned on (closed); if the current is removed, the switch is open: turned off.
Hardly rocket science, eh?
Let’s go back to the light switches, for a little more analogy.
Suppose you’re a spy, and you want to communicate a message to someone.
You’re on the 4th floor of a hotel, and there are 8 rooms along the corridor. It’s night. Your conspirator is in another hotel a few blocks away, but he can see the side of your hotel, and all 8 windows of the 4th floor.
You agree between you that turning on a light in one of the rooms means something.
You agree that you’re going to number the rooms LEFT to right, as
8 7 6 5 4 3 2 1.
If the light in room 1 is on, it means (you decide) “yes” and if the light in room #1 is off, it means “no.” And if you want to communicate a number, then if the light is on, it means “1″ and if it’s off, it means “0.”
So far so good, but that’s hardly much information. What if you wanted to communicate the alphabet? A bunch of numbers? You’ve only got 8 windows: how would you represent the letter “Q” then?
Hmmm…
You’re at a loss, but fortunately your friend has a thought. Since the lights can only be either on or off, that’s a grand total of two possible states. (“Bi” is the prefix meaning two, so since you can only have 1 or 0, on or off, you have a “binary” system here.)
All right then, what if window number 2 then means “2″ or “not 2″ then? Well, if the lights were off in room 2 and room 1 (which I’ll represent this way: 00) then there is no number two, and no number 1. The value 00 represents is Zero.
What about the lights on in both rooms? That would be 11. Yes: there’s a Two; yes – there’s a One. And 2 + 1 = 3. So the light both on would mean “3″ then.
And if only the one in room two were on? (10) – simple: 2-yes; 1-no. 2 + 0 = 2.
So, with only two rooms, we can represent four numbers: 0,1,2, and 3.
With 3 rooms then, we can end up lights on and off like this:
111 (all the light on)
011 (rooms two and one on; room three off)
001
000
101
110
100
001
So what does room Three represent? It’s the number 4.
Is there a 4? Yes/no.
Is there a 2? Yes/no
Is there a 1? Yes/no
if the answer is yes, yes, yes, that’s 111, which is 4 + 2 + 1 = 7.
011 is still 3
010 is still 2 (and so on)
101 is 4+0+1 = 5
Got it?
So we just carry on with this, making use of all 8 rooms.
Here’s what each room represents:
8 7 6 5 4 3 2 1
128 64 32 16 8 4 2 1
And if the lights are on or off like this:
00000011
that’s still “3″
and
10000001
is 128+0+0+0+0+0+0+1 = 129
Whee! Take a breather! Because that’s ALL THERE IS TO KNOW.
Really! That’s how computers represent numbers. They take 8 transistors; line them up in a row, and by applying electricity to some of them, and not to others, they can represent a number.
Yeah: it’s true that the largest number you can get into 8 switches is between zero and 255, but there’s nothing to stop you (OK: the computer) from ganging on another 8 more transistors, and reading all 16 at once.
32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
and that way it can represent a number between 0 and 65535.
This gets to go on forever leading to larger and larger numbers.
“Yeah” you say, “but what about letters of the alphabet?”
OK, let’s pretend that the on/off switches are letters instead.
00000000 = space
00000001 = a
00000010 = b
00000011 = c
and so on.
The switches do not change: we just agree that they have a different meaning. Cute eh?
0000001 either mean the number ONE or the letter A.
The switches have not changed at all… just how we agree to interpret them. So, a spreadsheet looks at 00001010 and interprets it as TEN, while in a word processor 00001010 is interpreted as the 10th letter of the alphabet – J. *
Let’s do a quick review: computers work by turning on and off little electrical switches, and then checking the state of a group of switches to see which ones are on and off. By looking at only a fixed amount of them, it can pretend those switches are a number, or a letter, or whatever it wants.
Now, let me let you in on the title of this piece. Computer programmers call one of those little switches a “bit”; they call 4 of them a “nibble”; 8 of them are called a “byte” and 2 or more bytes is a “word” (the number dependant on the particular computer in use.)
A “byte” (8-bits; 8 little on/off switches) is the most common one used, and when you hear people talking about memory size, or disk capacity, they are talking about “bytes.”
—-
OK: thinking about how those transistors work: they need electricity flowing to the third leg to keep the switches set. That’s why you lose all your work if the power goes off unexpectedly. Or even expectedly: turn off the electricity, and all the switches fall back to “off.”
This is not a “good thing” so we need a way to keep a recording of how those switches are set, so that we can reset them to the exact same state when we power up the computer again.
Fortunately, back in WWII, someone invented the tape recorder… and a hard disk is nothing but a tape recorder in a circle instead of a long stream of tape. Switches are just on/off, so recording little “bumps” in the coating of tape.. er, disk.. is pretty simple.
Record the switches states; turn off the machine. Turn on the machine; read back in the states and set the switches. Problem solved.
Well, almost: recording the whole entire state of the computer is pretty silly. If all I’ve done is write a letter to a friend (which is, as we now know, a huge long string of bytes) then all I really need to save is the range of computer memory that is holding those particular bytes, and not everything else.
No problem, we’ll just have the computer select only those bytes that are the letter, and save just those out.
And that, my friends, is what a “file” is on your hard drive. It’s a snapshot of the computer memory that applies to just one thing: your letter; some music; a video; a spreadsheet; a photograph… whatever.
They are all just long sequences of 00101110010100010101000101 which are recognized by some program as a letter, a spreadsheet and so on.
———
“OK” you say. “But when I sing a song, I’m not spitting out on/off commands; it’s a beautiful, perfectly pitched, graduating and sliding and connected set of tones and music. Heck: I’m the new Pavoratti! So how does the computer get all that into the on/off switches it can use?
Well, we’re talking about converting something into numbers… into digits. And the process is (cleverly enough) called “digitizing.”
Let’s consider the brighness of light, for example. Suppose we were going to digitize it into one bit. One bit can only be on or off, and so could represent only NO LIGHT or FULL BRIGHT.
Not very handy. Suppose we want to represent night (black), sunrise(grey) and noon(white). We might be able to do night and noon with one bit, but what about sunrise? How do we represent “not black and not fully white, but right inbetween?” Obviously we need another number.
So we use two bits. Two bits can represent 0, 1, 2, and 3.
We’re getting there: 0 represent black; 3 represents white. We have 1 and 2 left to represent dark grey, and light grey. Aha! Black; dark grey; light grey; white.
Not a very good representation of the nice smooth transition from black to white; night to day; but certainly better than just either night or day by itself.
Since there are no rocket scientists here, I’ll bet you’ve already figured out that if we break the black to white into 8 sections instead of four, we’re better off because we can represent even finer, smaller steps of gray.
And so it goes.
In fact then, suppose we use 256 steps. Why it might start becoming hard to tell the difference between one step and the one next to it.
So, with 256 steps, 0 would still be pure black, and 255 would be pure white, and middle grey would be 128. And there would be 127 steps on either side of middle grey which would make for pretty darned fine distinctions.
And that’s what “digitizing” does. Exactly and only. It starts out with some range of numbers, say 0-255, or 0-65535, or whatever, and then looks at whatever it’s digitizing (sound, light, pressure and so on) and assigns the highest number to “most”; the lowest number (zero) to “none” and all the rest a nice even breakdown of what’s in between.
If you have enough range, from zero to whatever, the human being listening to the result cfannot tell the difference between a nice smooth “real” transition, and one that is broken into thousands of little steps.
That, my friends, is digitizing.
“All good and well,” you say, “but I can tell the difference between more than 256 colors in a photograph.”
Aha…. so you can… but our eyes work not only with brightness, but with color as well… but probably not how you think.
Your eyes can distinguish 4 things: brightness; red, green, and blue. That’s it. It’s our brains that combine the red and the green and the blue to make all the other colors. Yep: pick a color, and I’ll tell you how much red there is in it; how much green; and how much blue.
Needless to say, this make life pretty simple (at least in principle) for computers and digital cameras.
Digital cameras.
There’s a thing called a “photovoltaic cell” which is just a fancy term for a bit of chemistry that is spread on a plate with a couple of wires coming off it. When light hits it, it generates a tiny amount of electricity in the wires. Not much mind you (which is why you need so many of those solar cells to recharge a battery, or power a house) but a measurable amount.
The more light, the more electricity. Less light; less electricity. No light; no electricity.
Now, suppose you put literally millions of those cells on a little tiny, one inch plate, and set it up so that you can read the electricity coming of each and every individual one of them. (Yeah: I know, not exactly easy, but that’s what really happens…!)
Throw a lens in front of it; focus the light on the little place, and lo and behold, you’ll get millions different voltages, each representing the brightness of the light that happened to hit each and every little cell.
Run those voltages through a digitizer, and get back out millions of numbers between 0 and 255.
And that, amigos, would be enough to represent a nice black and white photograph. Each cell would have its own level of brightness, from black to white, and 254 shades in between. (In the wonderful world of digital imaging, each of those “cells” is called a “picture element.” Thankfully, “picture element” has been shortened to “pixel.”)
“Um, OK. But where’s the color?”
Well, right you are: a pixel (cell) can only respond to brightness: the intensity of the light falling on it. So where does the color come from?
In another miracle of miniturization, those cell are each covered by a million little color filters, grouped together in threes. Yep: one red, one green and one blue. (OK, sticklers, there are two greens in each set, but let’s not confuse things here.)
By placing a colored filter over a cell, you filter out all but that color. What you end up with then is the intensity of the red; the intensity of the green, and the intensity of the blue; each one a number between 0 and 255.
And since the colors we see are combinations of red (R) green (G) and blue (B) [that's where "RGB" comes from] you have 256 x 256 x 256, for a total of over 16 Million (!) colors.
And I assure you that you cannot distinguish between 16 million different colors.
And -that- is why digital color photographs look just fine to human beings.
That is also how your digital camera works.
(There’s more to it, of course, including that since the pixels are side-by-side, how does one compensate for the other two ‘missing’ colors on each pixel? [Answer: it's done with fancy math.] But let’s keep it down to fundamental ideas here, and not get lost in the details…)
Once you take a photograph, all those millions of numbers are saved in a file (just like we noted above) in the memory of the digital camera. Plug it into your computer, and the file is transferred to your hard drive.
From there, Photoshop will load it in to your computer’s memory.
What?
OK, think of it this way: imagine your local post office, and the row upon row of post office boxes in the wall.
Each box is numbered. Let’s say the one on the upper left is number One and there are 100 of them, numbered one after the other: 1, 2, 3, 4, 5, 6… on to 98, 99, 100.
Someone comes along and places a slip of paper inside each box. On each slip of paper is a random number.
You can say “Show me the number in box 77.” Let’s say it’s 216. “Show me the number in box 78.” 154.
“Add one to the number in box 77.” 217. “Subtract 10 from the number in box 78.” 144. “Replace the number in box 77 with 43.” Now box 77 contains 43 instead of 217.
That is the basic analogy of how computer memory works. The number of a given box is its “address.”
When you load a file into computer memory, the first number in the file goes in the first (available) address; the second number in the file goes in the next address; the third number goes in the following address and so on, one after the other, in consecutive memory addresses.
If those numbers are from a photographic image and zero is darkest, and it gets brighter as you go higher up in numbers, then you can say “Add 10 to all the numbers in all the boxes” and this will have the effect of making the whole picture brighter.
—–
OK: I’m going to stop now. That’s enough of an introduction. I’ve skipped over a lot of the nitty gritty, and not so nitty-gritty, details in the hopes of providing a basic overview of how things work.
I hope that it’s helped some of you (including some writers, who should, but don’t) understand how computers and digitizing and memory works.