Sunday, May 15, 2011

(Digital) Camera vs. Eye

I am serious: the topic of this post is imaging, not physiology. This means I will not talk about how the eye camera works, but rather how the brain camera interprets images. Some physiology will nevertheless find its way through these lines, let us see how.
Let us begin with the easy thing: digital cameras. One main feature of all measurement devices is linearity, that is the ability to deliver a value directly proportional with the measured quantity (light, in our case).
If you think about it, that is a good thing: you can measure whatever value with a constant absolute precision. Do you want to use one inch precision to measure one foot in length? You have it! Do you want to measure the Earth-to-Moon distance with the same precision? There you go, but... what the sense in that? One inch is probably too much to measure with satisfactory precision one foot in length, and it is certainly nonsense for the Earth-to-Moon distance. I mean, what is the use of measuring 15 billion inches with one inch precision? And moreover, imagine you have a counter able to measure inches: one foot will be only 12" while Earth to Moon will be 15 billion inches, a number you can store in 34 bits. If able to perform such measurements, your counter would cover 11 orders of magnitude (from units to tenths of billions), not too bad!
But, what if you want to go and measure Sun distance? at almost 150 million km, that is 6'000 billion inches, a number you need 43 bits to represent, if you want to go with 1" precision. That is, covering 13 orders of magnitude.
Nature is wiser, it always was and will always be. When you see the Sun in its brightness, you are staring at something 20'000 billion times as bright as the faintest stars in a pitch-dark sky, a leap of 14 orders of magnitude to be covered with 45 bits. For a comparison, the precision of the raw format of DSLR cameras is 14 bits (from 0 to 16383 different levels); most pro CCD cameras use 16 bits (up to 65535), while only a few, very advanced cameras go up to 18 bits (up to 262'143).
How can eyes do better than our best technology, and in such a shameful (for the tech, of course) way? One reasonable reply is: “being reasonable”! First of all, we have already shown that a direct, linear correspondence between an input stimulus and the value we associate to it is not viable. As a first approximation, Nature uses logarithmic laws for this kind of things.
I know: logarithm is mathematics, and there are chances that you do hate mathematics, but there is no understanding without effort so, please, just follow my argument and I shall make my maths as simple as possible.

Logarithm function graph [source: Wikipedia]
Logarithm is a nice function, see it in the picture aside: it only grows (which is good for us, as we need higher sensations in reply to higher stimuli), it only exists for positive values (again, good for us, as there is nothing darker than no light at all, where we are going to fix our zero) and (now, for the hardest part) the rate of its growth decreases vs. the abscissa. The last property suits perfectly our needs, because it means that in reply to small stimuli in the dark (small x values) we get huge differences in the sensation, while big changes in high brightness (large x values) result in small sensation differences. You could say that this function tries to keep constant the relative precision of your sensations, i.e.: you perceive as different those stimuli that differ some given percent one from the other, independently of the stimulus you receive. Imagine that the value of this given percent is 10%, then you will see that a light stimulus of, say, 8, is different from 10, but 92 and 100 will be barely distinguishable, if ever.
Does this thing work? How well? In astronomy, for instance, light intensity of stars is given in magnitudes, and the difference between one magnitude and the next one is a constant, multiplicative factor of 2.512. Being multiplicative, two magnitudes in difference means 2.512 × 2.512 =2.5122. This means that light intensity can be measured by magnitudes with the inverse of a power law, i.e. a logarithm law. Is it that easy? Well, yes, and if it is good for astronomers, I assume it is good for me, and for you as well.
Actually, a more precise law is a power law, as those of you who already play with the gamma in their images know only too well, and magnitudes are nowadays measured with an hyperbolic sine law that handles some problems that may arise with logarithm in very dark images in a more robust way than logarithm does. Do not worry about that now, any difference with what I wrote up to now is inessential AND I will dedicate a post soon to both these topics (gamma and magnitudes) in a short time.
Is it enough? No other mistery than that? Well, sure there is, think about it: when you enter or get out of a tunnel while driving in a sunny day, chances are high that you will need some time in order to let your vision adapt to the new lighting conditions. What happens during this time?
This adaptation to the new light conditions allows you to see although with an ambient light 10'000 (that's it: ten thousand!) times as dim/bright as the previous conditions.
That is not an easy feat: the retina of your eyes is filled with rod and cone cells. The former are more sensitive to light and see in darkness, the latter are less sensitive BUT do distinguish colours. So, you do not actually cover the incredible luminosity range I wrote you about at any single time but, from time to time, your eyes adapt to the optimum sensitivity range. Don't ask me how eyes do that: they had millions of years to evolve to their perfection and I don't know any manufacturer wiser than Nature.

Why the eye is better than a camera at capturing contrast and faint detail simultaneously
[source: esciencenews.com]

So, is that all? Not yet. Up to now we have just seen how do our “detectors” (the eyes) work, but in human vision there is more that meets the eye (as the saying goes, and I find it quite appropriated to the discussion). The retina already adds something of its own by processing and manipulating the image in order to make it easier the task of analysing and understanding it. The main image processing technique operated by the eye is the edge enhancement, something you will find in your favourite picture processing software package, and able to make picture profiles sharper. In this way, the acknowledgement of shapes is easier, as they stand up over the image as the dark contour lines in a comic (so you know why kids draw so bold contours and comics are painted that way).
How does the filter works? As you can see in the image, retina cells on the bright side of a luminosity transition shut down their neighbours on the dark side, therefore making the transition look stronger.

EDIT (17/05/2011) - sorry for closing the post this way: it was late night and I completely forgot to write down a proper ending. Nonetheless, that's all, it's over. I hope you liked it and will comment about it.
See you for the next post,
Marino

Saturday, May 7, 2011

Camera Lenses: Technical Excellence

In my previous post I advised to make up an idea about what you actually need, before going and buy a camera. I also discussed the different sources of information needed to make up this opinion, warmly counselling the DPreview website.
A good camera (that is, DSLR) will allow you to capture a good image if provided with a lens fit for your application/subject of interest. For instance, I love astrophotography (more on this in next posts, I promise), which means I should be using wide lenses (in order to capture more light) and fast ones (in order to capture that light in a small time).
But I also like macro photography of flowers and small objects, so that I would need macro lenses too (that is, lenses able to focus objects at very short distances, say 25 cm or even less) in order to capture those tiny details.
And then there are different requirements for landscapes or portraits. In the former case, software programs allow stitching contiguous images of a given panorama together in order to build up a much bigger image in terms of pixels, thus allowing even small cameras to produce very nice results. On the other side, the camera optics should be as aberration-free as possible in order to allow better scene reconstruction. The only disadvantage of this technique is that something may move from one frame to the next one (waves at sea, for instance), thus rendering impossible the image stitching.
The other way is to buy a wide-angle lens (typically, less than 28 mm focal length on a 35 mm sensor) and capture the whole landscape in only one shot. The problem here is that you are resolution-limited by the camera you are using, and if you plan to make wide enlargements of the picture, pixellation of the image will show up.
As for portraits, very typical focal lengths (say, from 50 to 85 mm with a 35 mm sensor size) will come handy, as you want to reproduce a scene in a manner as similar to what your eyes see as possible. Part of this resemblance is also given by a concept defined by a Japanese word: the bokeh.
On Wikipedia (for those like me who do not dominate Japanese) bokeh is the blur, or the aesthetic quality of the blur, in out-of-focus areas of an image.
In other words, a good photographer is able to picture the subject and its surroundings, and make you see it as if you were there. But, as your eyes cannot focus at the same time objects near and far, a good photographer will also try to emulate this phenomenon by using a small depth of field with his camera, i.e. the subject of his picture will be razor-sharp but everything else will be nicely blurred.
In its turn, a small depth of field is obtained with wide lens aperture values (f values not bigger than 2.8). This means that a desirable requisite for a good lens dedicated to portraits is a wide aperture, which means money.
I could go on and on with examples, the bottom line is: know what you want it for, then you know what you want! More important is where to look for information that will allow you to compare among the huge amount of lenses in the market or discontinued.
A first advise may well be DPreview again: here you find the page for the lens reviews, with plenty of information and comparisons (just like we saw for cameras), but I want to introduce you to an even better website, for the kind of use we have in mind: photodo.
Why do I say that photodo is so better than dpreview? For one simple reason: MTF, Modulation Transfer Function. I beg your pardon if I try to use some “scientifically professional” concept on these pages, but the simple fact that I find it used on a website not scientifically committed makes me believe that amateurs too will take advantage applying it.
Here you find a definition for MTF. Let us see what it means.
Let us consider a comb with teeth with variable spacing. We can assume that the alternated pattern tooth-space-tooth can be seen as a sharp sequence 0-1-0 (or 1-0-1, doesn't matter). If we try to take a picture of this pattern with a camera, it will be converted to a sequence of blacks and whites, the steeper as the detector pixels are tinier (as they better represent the actual pattern) and the teeth are more spaced and opaque.
For any given spacing (spatial frequency) of the teeth, the MTF tells you how good your image represents the actual comb pattern, assuming any value between 0 and 1, with 0 meaning that the comb is actually rendered as a perfectly flat object and 1 meaning that the comb pattern is perfectly reproduced in shape and intensity.
At photodo they make this simple thing: they take pictures of a standard pattern representing various spatial frequencies through virtually any lens there is/was in the market, then they rate it on a scale of five depending on different parameters but, as I was saying before, MTF is one of these. They are so strict that no lens has earned yet the 5 stars rating but, on the other side, this means that any lens with a rating higher than 4 can be considered as very good, top class or excellent.
You will find any kind of lens, some with the MTF graph, so that you can compare form a pure mathematical point of view the quality of your lenses. Through this link, for instance, you have all of their lenses sorted in descending quality order. I hope you find it interesting and helpful.