A place to cache linked articles (think custom and personal wayback machine)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Cameras and Lenses (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f0f0ea">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f0f0ea">
  26. <!-- Documented, feel free to shoot an email. -->
  27. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  28. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  32. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <script>
  36. function toggleTheme(themeName) {
  37. document.documentElement.classList.toggle(
  38. 'forced-dark',
  39. themeName === 'dark'
  40. )
  41. document.documentElement.classList.toggle(
  42. 'forced-light',
  43. themeName === 'light'
  44. )
  45. }
  46. const selectedTheme = localStorage.getItem('theme')
  47. if (selectedTheme !== 'undefined') {
  48. toggleTheme(selectedTheme)
  49. }
  50. </script>
  51. <meta name="robots" content="noindex, nofollow">
  52. <meta content="origin-when-cross-origin" name="referrer">
  53. <!-- Canonical URL for SEO purposes -->
  54. <link rel="canonical" href="https://ciechanow.ski/cameras-and-lenses/">
  55. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick">
  56. <article>
  57. <header>
  58. <h1>Cameras and Lenses</h1>
  59. </header>
  60. <nav>
  61. <p class="center">
  62. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  63. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  64. </svg> Accueil</a> •
  65. <a href="https://ciechanow.ski/cameras-and-lenses/" title="Lien vers le contenu original">Source originale</a>
  66. </p>
  67. </nav>
  68. <hr>
  69. <p>Pictures have always been a meaningful part of the human experience. From the first cave drawings, to sketches and paintings, to modern photography, we&rsquo;ve mastered the art of recording what we see.</p>
  70. <p>Cameras and the lenses inside them may seem a little mystifying. In this blog post I&rsquo;d like to explain not only how they work, but also how adjusting a few tunable parameters can produce fairly different results:</p>
  71. <div class="drawer_container double_drawer" id="lens_hero"></div>
  72. <div class="lens_yellow" id="lens_hero_sl2"></div>
  73. <div class="lens_blue" id="lens_hero_sl1"></div>
  74. <div class="lens_black" id="lens_hero_sl0"></div>
  75. <p>Over the course of this article we&rsquo;ll build a simple camera from first principles. Our first steps will be very modest – we&rsquo;ll simply try to take any picture. To do that we need to have a sensor capable of detecting and measuring light that shines onto it.</p>
  76. <h1 id="recording-light">Recording Light<a href="https://ciechanow.ski/cameras-and-lenses/#recording-light" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  77. <p>Before the dawn of the digital era, photographs were taken on a piece of film covered in crystals of <a href="https://en.wikipedia.org/wiki/Silver_halide">silver halide</a>. Those compounds are light-sensitive and when exposed to light they form a speck of metallic silver that can later be developed with further chemical processes.</p>
  78. <p>For better or for worse, I&rsquo;m not going to discuss analog devices – these days most cameras are digital. Before we continue the discussion relating to light we&rsquo;ll use the classic trick of turning the illumination off. Don&rsquo;t worry though, we&rsquo;re not going to stay in darkness for too long.</p>
  79. <p><br></p>
  80. <div class="dark_light_bg_grad_top"></div>
  81. <div class="dark_light_bg"><div class="bg_content">
  82. <p><br></p>
  83. <p>The <a href="https://en.wikipedia.org/wiki/Image_sensor">image sensor</a> of a digital camera consists of a grid of photodetectors. A&nbsp;photodetector converts photons into electric current that can be measured – the more photons hitting the detector the higher the signal.</p>
  84. <p>In the demonstration below you can observe how photons fall onto the arrangement of detectors represented by small squares. After some processing, the value read by each detector is converted to the brightness of the resulting image pixels which you can see on the right side. I&rsquo;m also symbolically showing which <em>photosite</em> was hit with a short highlight. The slider below controls the flow of time:</p>
  85. <div class="drawer_container double_drawer" id="lens_detector"></div>
  86. <div class="long_slider" id="lens_detector_sl0"></div>
  87. <p>The longer the time of collection of photons the more of them are hitting the detectors and the brighter the resulting pixels in the image. When we don&rsquo;t gather enough photons the image is <a href="#" class="link_button" onclick="lens_under_exp();return false;">underexposed</a>, but if we allow the photon collection to run for too long the image will be <a href="#" class="link_button" onclick="lens_over_exp();return false;">overexposed</a>.</p>
  88. <p>While the photons have the &ldquo;color&rdquo; of their <a href="https://ciechanow.ski/color-spaces/#and-there-was-light">wavelength</a>, the photodetectors don&rsquo;t see that hue – they only measure the total intensity which results in a black and white image. To record the color information we need to separate the incoming photons into distinct groups. We can put tiny color filters on top of the detectors so that they will only accept, more or less, red, green, or blue light:</p>
  89. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_rgb_filter"></div>
  90. <div id="lens_rgb_filter_sl0"></div>
  91. <p>This <a href="https://en.wikipedia.org/wiki/Color_filter_array">color filter array</a> can be arranged in many different formations. One of the simplest is a <a href="https://en.wikipedia.org/wiki/Bayer_filter">Bayer filter</a> which uses one red, one blue, and <em>two</em> green filters arranged in a 2x2 grid:</p>
  92. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_bayer"></div>
  93. <p>A Bayer filter uses two green filters because light in green part of the spectrum heavily <a href="https://en.wikipedia.org/wiki/Luminosity_function">correlates</a> with perceived brightness. If we now repeat this pattern across the entire sensor we&rsquo;re able to collect color information. For the next demo we will also double the resolution to an astonishing 1 kilopixel arranged in a 32x32 grid:</p>
  94. <div class="drawer_container double_drawer" id="lens_detector_rgbg"></div>
  95. <div class="long_slider" id="lens_detector_rgbg_sl0"></div>
  96. <p>Note that the individual sensors themselves still only see the intensity, and not the color, but knowing the arrangement of the filters we can recreate the colored intensity of each sensor, as shown on the right side of the simulation.</p>
  97. <p>The final step of obtaining a normal image is called <a href="https://en.wikipedia.org/wiki/Demosaicing"><em>demosaicing</em></a>. During demosaicing we want to reconstruct the full color information by filling in the gaps in the captured RGB values. One of the simplest way to do it is to just linearly interpolate the values between the existing neighbors. I&rsquo;m not going to focus on the details of many other available demosaicing algorithms and I&rsquo;ll just present the resulting image created by the process:</p>
  98. <div class="drawer_container double_drawer" id="lens_detector_rgb"></div>
  99. <div class="long_slider" id="lens_detector_rgb_sl0"></div>
  100. <p>Notice that yet again the overall brightness of the image depends on the length of time for which we let the photons through. That duration is known as <a href="https://en.wikipedia.org/wiki/Shutter_speed"><em>shutter speed</em></a> or exposure time. For most of this presentation I will ignore the time component and we will simply assume that the shutter speed has been set <em>just right</em> so that the image is well exposed.</p>
  101. <p>The examples we&rsquo;ve discussed so far were very convenient – we were surrounded by complete darkness with the photons neatly hitting the pixels to form a coherent image. Unfortunately, we can&rsquo;t count on the photon paths to be as favorable in real environments, so let&rsquo;s see how the sensor performs in more realistic scenarios.</p>
  102. <p><br></p>
  103. </div>
  104. </div>
  105. <div class="dark_light_bg_grad_bottom"></div>
  106. <p><br></p>
  107. <p>Over the course of this article we will be taking pictures of this simple scene. The almost white background of this website is also a part of the scenery – it represents a bright overcast sky. You can drag around the demo to see it from other directions:</p>
  108. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_scene"></div>
  109. <p>Let&rsquo;s try to see what sort of picture would be taken by a sensor that is placed near the objects without any enclosure. I&rsquo;ll also significantly increase the sensor&rsquo;s resolution to make the pixels of the final image align with the pixels of your display. In the demonstration below the left side represents a view of the scene with the small greenish sensor present, while the right one shows the taken picture:</p>
  110. <div class="drawer_container double_drawer" id="lens_bare_film"></div>
  111. <p>This is not a mistake. As you can see, the obtained image doesn&rsquo;t really resemble anything. To understand why this happens let&rsquo;s first look at the light radiated from the scene.</p>
  112. <p>If you had a chance to explore how <a href="https://ciechanow.ski/lights-and-shadows/#reflections">surfaces reflect light</a>, you may recall that most matte surfaces scatter the incoming light in every direction. While I&rsquo;m only showing a few examples, <em>every</em> point on every surface of this scene reflects the photons it receives from the whiteish background light source all around itself:</p>
  113. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_scene_rays"></div>
  114. <p>The red sphere ends up radiating red light, the green sphere radiates green light, and the gray checkerboard floor reflects white light of lesser intensity. Most importantly, however, the light emitted from the background is <em>also</em> visible to the sensor.</p>
  115. <p>The problem with our current approach to taking pictures is that every pixel of the sensor is exposed to the <em>entire</em> environment. Light radiated from every point of the scene and the white background hits every point of the sensor. In the simulation below you can witness how light from different directions hits one point on the surface of the sensor:</p>
  116. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_sensor_rays"></div>
  117. <p>Clearly, to obtain a discernible image we have to limit the range of directions that affect a given pixel on the sensor. With that in mind, let&rsquo;s put the sensor in a box that has a small hole in it. The first slider controls the <span class="lens_black">diameter</span> of the hole, while the second one controls the <span class="lens_yellow">distance</span> between the opening and the sensor:</p>
  118. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_box"></div>
  119. <div class="lens_black" id="lens_box_sl0"></div>
  120. <div class="lens_yellow" id="lens_box_sl1"></div>
  121. <p>While not shown here, the inner sides of the walls are all black so that no light is reflected inside the box. I also put the sensor on the back wall so that the light from the hole shines onto it. We&rsquo;ve just built a <a href="https://en.wikipedia.org/wiki/Pinhole_camera"><em>pinhole camera</em></a>, let&rsquo;s see how it performs. Observe what happens to the taken image as we tweak the <span class="lens_black">diameter</span> of the hole with the first slider, or change the <span class="lens_yellow">distance</span> between the opening and the sensor with the second one:</p>
  122. <div class="drawer_container double_drawer" id="lens_film"></div>
  123. <div class="lens_black" id="lens_film_sl0"></div>
  124. <div class="lens_yellow" id="lens_film_sl1"></div>
  125. <p>There are so many interesting things happening here! The most pronounced effect is that the image is inverted. To understand why this happens let&rsquo;s look at the schematic view of the scene that shows the light rays radiated from the objects, going through the hole, and hitting the sensor:</p>
  126. <div class="drawer_container double_drawer move_cursor" id="lens_film_invert"></div>
  127. <p>As you can see the rays cross over in the hole and the formed image is a horizontal and a vertical reflection of the actual scene. Those two flips end up forming a 180&deg; rotation. Since rotated images aren&rsquo;t convenient to look at, all cameras automatically rotate the image for presentation and for the rest of this article I will do so as well.</p>
  128. <p>When we change the <span class="lens_yellow">distance</span> between the hole and the sensor the viewing angle changes drastically. If we trace the rays falling on the corner pixels of the sensor we can see that they define the extent of the visible section of the scene:</p>
  129. <div class="drawer_container double_drawer" id="lens_frustum"></div>
  130. <div class="lens_yellow" id="lens_frustum_sl0"></div>
  131. <p>Rays of light coming from outside of that shape still go through the pinhole, but they land outside of the sensor and aren&rsquo;t recorded. As the hole moves further away from the sensor, the angle, and thus the <a href="https://en.wikipedia.org/wiki/Field_of_view">field of view</a> visible to the sensor gets smaller. We can see this in a top-down view of the camera:</p>
  132. <div class="drawer_container double_drawer" id="lens_field"></div>
  133. <div class="lens_yellow" id="lens_field_sl0"></div>
  134. <p>Coincidentally, this diagram also helps us explain two other effects. Firstly, in the photograph the red sphere looks almost as big as the green one, even though the scene view shows the latter is much larger. However, both spheres end up occupying roughly <a href="#" class="link_button" onclick="lens_field_0();return false;">the same span</a> on the sensor and their size in the picture is similar. It&rsquo;s also worth noting that the spheres seem to grow when the field of view gets narrower because their light covers larger part of the sensor.</p>
  135. <p>Secondly, notice that different pixels of the sensor have different distance and relative orientation to the hole. The pixels right in the center of the sensor see the pinhole straight on, but pixels positioned at an angle to the main axis see a distorted pinhole that is further away. The ellipse in the bottom right corner of the demonstration below shows how a pixel positioned at the blue point sees the pinhole:</p>
  136. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_hole_pixel_view"></div>
  137. <div class="lens_blue" id="lens_hole_pixel_view_sl0"></div>
  138. <p>This change in the visible area of the hole causes the darkening we see in the corners of the photograph. The value of the <em>cosine</em> of the angle I&rsquo;ve marked with a <span class="lens_yellow">yellow color</span> is quite important as it contributes to the reduction of visible light in four different ways:</p>
  139. <ul>
  140. <li>Two cosine factors from the increased distance to the hole, it&rsquo;s essentially the <a href="https://ciechanow.ski/lights-and-shadows/#inverse_square">inverse square law</a></li>
  141. <li>A cosine factor from the side squeeze of the circular hole seen at an angle</li>
  142. <li>A cosine factor from the relative <a href="https://ciechanow.ski/lights-and-shadows/#cosine_factor">tilt of the receptor</a></li>
  143. </ul>
  144. <p>These four factors conspire together to reduce the illumination by a factor of <strong>cos<sup>4</sup>(&alpha;)</strong> in what is known as <em>cosine-fourth-power law</em>, also described as <a href="https://en.wikipedia.org/wiki/Vignetting#Natural_vignetting">natural vignetting</a>.</p>
  145. <p>Since we know the relative geometry of the camera and the opening we can correct for this effect by simply dividing by the falloff factor and from this point on I will make sure that the images don&rsquo;t have darkened corners.</p>
  146. <p>The final effect we can observe is that when the hole gets smaller the image gets sharper. Let&rsquo;s see how the light radiated from two points of the scene ends up going through the camera depending on the <span class="lens_black">diameter</span> of the pinhole:</p>
  147. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_hole_solid_angle"></div>
  148. <div class="lens_black" id="lens_hole_solid_angle_sl0"></div>
  149. <p>We can already see that larger hole size ends up creating a bigger spread on the sensor. Let&rsquo;s see this situation up close on a simple grid of detecting cells. Notice what happens to the size of the final circle hitting the sensor as that <span class="lens_black">diameter</span> of the hole changes:</p>
  150. <div class="drawer_container lens_long_drawer medium_drawer move_cursor" id="lens_hole_sharpness"></div>
  151. <div class="lens_black" id="lens_hole_sharpness_sl0"></div>
  152. <p>When the hole is <a href="#" class="link_button" onclick="lens_sharp_0();return false;">small enough</a> rays from the source only manage to hit one pixel on the sensor. However, at <a href="#" class="link_button" onclick="lens_sharp_1();return false;">larger radii</a> the light spreads onto other pixels and a tiny point in the scene is no longer represented by a single pixel causing the image to no longer be sharp.</p>
  153. <p>It&rsquo;s worth pointing out that sharpness is ultimately arbitrary – it depends on the size at which the final image is seen, viewing conditions, and visual acuity of the observer. The same photograph that looks sharp on a postage stamp may in fact be very blurry when seen on a big display.</p>
  154. <p>By reducing the size of the cone of light we can make sure that the source light affects a limited number of pixels. Here, however, lays the problem. The sensor we&rsquo;ve been using so far has been an idealized detector capable of flawless adjustment of its sensitivity to the lighting conditions. If we instead were to fix the sensor sensitivity adjustment, the captured image would look more like this:</p>
  155. <div class="drawer_container double_drawer" id="lens_film_exposure"></div>
  156. <div class="lens_black" id="lens_film_exposure_sl0"></div>
  157. <div class="lens_yellow" id="lens_film_exposure_sl1"></div>
  158. <p>As the relative size of the hole visible to the pixels of the sensor gets smaller, be it due to reduced <span class="lens_black">diameter</span> or increased <span class="lens_yellow">distance</span>, fewer photons hit the surface and the image gets dimmer.</p>
  159. <p>To increase the number of photons we capture we could extend the duration of collection, but increasing the exposure time comes with its own problems – if the photographed object moves or the camera isn&rsquo;t held steady we risk introducing some <a href="https://en.wikipedia.org/wiki/Motion_blur">motion blur</a>.</p>
  160. <p>Alternatively, we could increase the <a href="https://en.wikipedia.org/wiki/Film_speed">sensitivity</a> of the sensor which is described using the ISO rating. However, boosting the ISO may introduce a higher level of <a href="https://en.wikipedia.org/wiki/Image_noise">noise</a>. Even with these problems solved an actual image obtained by smaller and smaller holes would actually start getting blurry again due to <a href="https://en.wikipedia.org/wiki/Diffraction">diffraction</a> effects of light.</p>
  161. <p>If you recall how diffuse surfaces reflect light you may also realize how incredibly inefficient a pinhole camera is. A single point on the surface of an object radiates light into its surrounding hemisphere, however, the pinhole captures only a tiny portion of that light.</p>
  162. <p>More importantly, however, a pinhole camera gives us minimal artistic control over <em>which</em> parts of the picture are blurry. In the demonstration below you can witness how changing which object is in focus heavily affects what is the primary target of attention of the photograph:</p>
  163. <div class="drawer_container double_drawer" id="lens_focus_demo"></div>
  164. <div id="lens_focus_demo_sl0"></div>
  165. <p>Let&rsquo;s try to build an optical device that would solve both of these problems: we want to find a way to harness a bigger part of the energy radiated by the objects and also control what is blurry and <em>how</em> blurry it is. For the objects in the scene that are supposed to be sharp we want to collect a big chunk of their light and make it converge to the smallest possible point. In essence, we&rsquo;re looking for an instrument that will do something like this:</p>
  166. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_device"></div>
  167. <p>We could then put the sensor at the focus point and obtain a sharp image. Naturally, the contraption we&rsquo;ll try to create has to be transparent so that the light can pass through it and get to the sensor, so let&rsquo;s begin the investigation by looking at a piece of glass.</p>
  168. <h1 id="glass">Glass<a href="https://ciechanow.ski/cameras-and-lenses/#glass" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  169. <p>In the demonstration below I put a red stick behind a pane of glass. You can adjust the thickness of this pane with the <span class="lens_gray">gray slider</span> below:</p>
  170. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_glass"></div>
  171. <div id="lens_glass_sl0"></div>
  172. <p>When you look at the stick through the surface of a thick glass <a href="#" class="link_button" onclick="lens_glass_0();return false;">straight on</a>, everything looks normal. However, as your viewing direction <a href="#" class="link_button" onclick="lens_glass_1();return false;">changes</a> the stick seen through the glass seems out of place. The thicker the glass and the steeper the viewing angle the bigger the offset.</p>
  173. <p>Let&rsquo;s focus on one point on the surface of the stick and see how the rays of light radiated from its surface propagate through the subsection of the glass. The <span class="lens_red">red slider</span> controls the position of the source and the <span class="lens_gray">gray slider</span> controls the thickness. You can drag the demo around to see it from different viewpoints:</p>
  174. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_glass_rays"></div>
  175. <div class="lens_red" id="lens_glass_rays_sl0"></div>
  176. <div id="lens_glass_rays_sl1"></div>
  177. <p>For some reason the rays passing through glass at an angle are <a href="#" class="link_button" onclick="lens_glass_rays_0();return false;">deflected off their paths</a>. The change of direction happens whenever the ray enters or leaves the glass.</p>
  178. <p>To understand <em>why</em> the light changes direction we have to peek under the covers of <a href="https://en.wikipedia.org/wiki/Classical_electromagnetism">classical electromagnetism</a> and talk a bit more about waves.</p>
  179. <h1 id="waves">Waves<a href="https://ciechanow.ski/cameras-and-lenses/#waves" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  180. <p>It&rsquo;s impossible to talk about wave propagation without involving the time component, so the simulations in this sections are animated – you can play and pause them by <span class="click_word">clicking</span><span class="tap_word">tapping</span> on the button in their bottom left corner.</p>
  181. <p>By default all animations are <span id="global_animate_on">enabled, but if you find them distracting, or if you want to save power, you can <a href="#" class="link_button" onclick="global_animate(false);return false;">globally pause</a> all the following demonstrations.</span><span id="global_animate_off" class="hidden">disabled, but if you&rsquo;d prefer to have things moving as you read you can <a href="#" class="link_button" onclick="global_animate(true);return false;">globally unpause</a> them and see all the waves oscillating.</span></p>
  182. <p>Let&rsquo;s begin by introducing the simplest sinusoidal wave:</p>
  183. <div class="drawer_container double_drawer" id="lens_sine"></div>
  184. <div class="lens_black" id="lens_sine_sl0"></div>
  185. <div id="lens_sine_sl1"></div>
  186. <p>A wave like this can be characterized by two components. <a href="https://en.wikipedia.org/wiki/Wavelength">Wavelength</a> <strong>&lambda;</strong> is the distance over which the shape of the wave repeats. Period <strong>T</strong> defines how much time a full cycle takes.</p>
  187. <p><a href="https://en.wikipedia.org/wiki/Frequency">Frequency</a> <strong>f</strong>, is just a reciprocal of period and it&rsquo;s more commonly used – it defines how many waves per second have passed over some fixed point. Wavelength and frequency define <a href="https://en.wikipedia.org/wiki/Phase_velocity">phase velocity</a> <strong>v<sub>p</sub></strong> which describes how quickly a point on a wave, e.g. a peak, moves:</p>
  188. <div class="equation">
  189. <span class="equation_frac">v<sub>p</sup></span> = <span class="equation_frac">&lambda;</span> &middot; <span class="equation_frac">f</span>
  190. </div>
  191. <p>The sinusoidal wave is the building block of a polarized electromagnetic plane wave. As the name implies electromagnetic radiation is an interplay of oscillations of electric field <strong>E</strong> and magnetic field <strong>B</strong>:</p>
  192. <div class="drawer_container double_drawer move_cursor" id="lens_em"></div>
  193. <p>In an electromagnetic wave the magnetic field is tied to the electric field so I&rsquo;m going to hide the former and just visualize the latter. Observe what happens to the electric component of the field as it passes through a block of glass. I need to note that dimensions of wavelengths are <em>not</em> to scale:</p>
  194. <div class="drawer_container move_cursor" id="lens_wave_glass"></div>
  195. <p>Notice that the wave remains continuous at the boundary and inside the glass the frequency of the passing wave remains constant, However, the wavelength and thus the phase velocity are reduced – you can see it clearly <a href="#" class="link_button" onclick="lens_wave_glass_0();return false;">from the side</a>.</p>
  196. <p>The microscopic reason for the phase velocity change is <a href="https://en.wikipedia.org/wiki/Ewald–Oseen_extinction_theorem">quite complicated</a>, but it can be quantified using the <a href="https://en.wikipedia.org/wiki/Refractive_index"><em>index of refraction</em></a> <strong>n</strong>, which is the ratio of the speed of light <strong>c</strong> to the phase velocity <strong>v<sub>p</sub></strong> of lightwave in that medium:</p>
  197. <div class="equation">
  198. <span class="equation_frac">n</span> = <span class="equation_frac"><span>c</span>
  199. <span class="equation_div_symbol">/</span>
  200. <span class="lns_div_bottom">v<sub>p</sub></span>
  201. </span>
  202. </div>
  203. <p>The higher the index of refraction the <em>slower</em> light propagates through the medium. In the table below I&rsquo;ve presented a few different indices of refraction for some materials:</p>
  204. <table>
  205. <tr><td class="lens_list_item_material">vacuum</td><td class="lens_list_item_index">1.00</td></tr>
  206. <tr><td class="lens_list_item_material">air</td><td class="lens_list_item_index">1.0003</td></tr>
  207. <tr><td class="lens_list_item_material">water</td><td class="lens_list_item_index">1.33</td></tr>
  208. <tr><td class="lens_list_item_material">glass</td><td class="lens_list_item_index">1.53</td></tr>
  209. <tr><td class="lens_list_item_material">diamond</td><td class="lens_list_item_index">2.43</td></tr>
  210. </table>
  211. <p>Light traveling through air barely slows down, but in a diamond it&rsquo;s over twice as slow. Now that we understand how <span class="lens_black">index of refraction</span> affects the wavelength in the glass, let&rsquo;s see what happens when we change the <span class="lens_gray">direction</span> of the incoming wave:</p>
  212. <div class="drawer_container move_cursor" id="lens_wave_glass2"></div>
  213. <div class="lens_black" id="lens_wave_glass2_sl0"></div>
  214. <div id="lens_wave_glass2_sl1"></div>
  215. <p>The wave in the glass has a shorter wavelength, but it still has to match the positions of its peaks and valleys across the boundary. As such, the direction of propagation <a href="#" class="link_button" onclick="lens_wave_glass_2();return false;">must change</a> to ensure that continuity.</p>
  216. <p>I need to note that the previous two demonstrations presented a two dimensional wave since that allowed me to show the sinusoidal component oscillating into the third dimension. In real world the lightwaves are three dimensional and I can&rsquo;t really visualize the sinusoidal component without using the fourth dimension which has <a href="https://ciechanow.ski/tesseract/">its own set of complications</a>.</p>
  217. <p>The alternative way of presenting waves is to use <a href="https://en.wikipedia.org/wiki/Wavefront"><em>wavefronts</em></a>. Wavefronts connect the points of the same phase of the wave, e.g. all the peaks or valleys. In two dimensions wavefronts are represented by lines:</p>
  218. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_wave_2d"></div>
  219. <p>In three dimensions the wavefronts are represented by <em>surfaces</em>. In the demonstration below a single source emits a spherical wave, points of the same phase in the wave are represented by the moving shells:</p>
  220. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_wave_3d"></div>
  221. <p>By drawing lines that are perpendicular to the surface of the wavefront we create the familiar rays. In this interpretation rays simply show the local direction of wave propagation which can be seen in this example of a section of a spherical 3D wave:</p>
  222. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_wave_rays"></div>
  223. <p>I will continue to use the ray analogy to quantify the change in direction of light passing through materials. The relation between the angle of incidence <strong>&theta;<sub>1</sub></strong> and angle of refraction <strong>&theta;<sub>2</sub></strong> can be formalized with the equation known as <a href="https://en.wikipedia.org/wiki/Snell%27s_law">Snell&rsquo;s law</a>:</p>
  224. <div class="equation">
  225. <span class="lens_blue">n<sub>1</sub></span> &middot; sin(&theta;<sub>1</sub>) = <span class="lens_yellow">n<sub>2</sub></span> &middot; sin(&theta;<sub>2</sub>)
  226. </div>
  227. <p>It describes how a ray of light changes direction relative to the surface normal on the border between two different media. Let&rsquo;s see it in action:</p>
  228. <div class="drawer_container square_drawer small_drawer" id="lens_snell"></div>
  229. <div class="lens_black" id="lens_snell_sl0"></div>
  230. <div class="lens_blue" id="lens_snell_sl1"></div>
  231. <div class="lens_yellow" id="lens_snell_sl2"></div>
  232. <p>When traveling from a less to more refractive material the ray bends <a href="#" class="link_button" onclick="lens_snell_0();return false;"><em>towards</em> the normal</a>, but when the ray exits the object with higher index of refraction it bends <a href="#" class="link_button" onclick="lens_snell_1();return false;"><em>away</em> from the normal</a>.</p>
  233. <p>Notice that in <a href="#" class="link_button" onclick="lens_snell_2();return false;">some configurations</a> the refracted ray completely disappears, however, this doesn&rsquo;t paint a full picture because we&rsquo;re currently completely ignoring reflections.</p>
  234. <p>All transparent objects reflect some amount of light. You may have noticed that reflection on a surface of a calm lake or even on the other side of the glass demonstration at the beginning of the <a href="#glass">previous section</a>. The intensity of that reflection depends on the index of refraction of the material and the angle of the incident ray. Here&rsquo;s a more realistic demonstration of how light would get refracted <em>and</em> reflected between two media:</p>
  235. <div class="drawer_container square_drawer small_drawer" id="lens_snell2"></div>
  236. <div class="lens_black" id="lens_snell2_sl0"></div>
  237. <div class="lens_blue" id="lens_snell2_sl1"></div>
  238. <div class="lens_yellow" id="lens_snell2_sl2"></div>
  239. <p>The relation between <em>transmittance</em> and <em>reflectance</em> is determined by <a href="https://en.wikipedia.org/wiki/Fresnel_equations">Fresnel equations</a>. Observe that the curious case of missing light that we saw previously <a href="#" class="link_button" onclick="lens_snell_3();return false;">no longer occurs</a> – that light is actually reflected. The transition from partial reflection and refraction to the complete reflection is continuous, but near the end it&rsquo;s very rapid and at some point the refraction <a href="#" class="link_button" onclick="lens_snell_4();return false;">completely disappears</a> in the effect known as <a href="https://en.wikipedia.org/wiki/Total_internal_reflection">total internal reflection</a>.</p>
  240. <p>The <a href="https://en.wikipedia.org/wiki/Total_internal_reflection#Critical_angle"><em>critical angle</em></a> at which the total internal reflection starts to happen depends on the indices of refraction of the boundary materials. Since that coefficient is low for air, but very high for diamond a <a href="https://en.wikipedia.org/wiki/Brilliant_(diamond_cut)">proper cut</a> of the faces <a href="https://physics.stackexchange.com/questions/43361/why-do-diamonds-shine/43373#43373">makes diamonds</a> very shiny.</p>
  241. <p>While interesting on its own, reflection in glass isn&rsquo;t very relevant to our discussion and for the rest of this article we&rsquo;re not going to pay much attention to it. Instead, we&rsquo;ll simply assume that the materials we&rsquo;re using are covered with high quality <a href="https://en.wikipedia.org/wiki/Anti-reflective_coating">anti-reflective coating</a>.</p>
  242. <h1 id="manipulating-rays">Manipulating Rays<a href="https://ciechanow.ski/cameras-and-lenses/#manipulating-rays" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  243. <p>Let&rsquo;s go back to the example that started the discussion of light and glass. When both sides of a piece of glass are parallel, the ray is shifted, but it still travels in the same direction. Observe what happens to the ray when we change the relative angle of the surfaces of the glass.</p>
  244. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_parallel"></div>
  245. <div id="lens_parallel_sl0"></div>
  246. <p>When we make two surfaces of the glass <em>not</em> parallel we gain the ability to change the direction of the rays. Recall, that we&rsquo;re trying to make the rays hitting the optical device <em>converge</em> at a certain point. To do that we have to bend the rays in the upper part down and, conversely, bend the rays in the lower part up.</p>
  247. <p>Let&rsquo;s see what happens if we shape the glass to have different angles between its walls at different height. In the demonstration below you can control how many distinct segments a piece of glass is shaped to:</p>
  248. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_subdiv"></div>
  249. <div id="lens_subdiv_seg0"></div>
  250. <p>As the number of segments <a href="#" class="link_button" onclick="lens_subdiv_0();return false;">approaches infinity</a> we end up with a continuous surface without any edges. If we look at the crossover point <a href="#" class="link_button" onclick="lens_subdiv_1();return false;">from the side</a> you may notice that we&rsquo;ve managed to converge the rays across one axis, but the top-down view <a href="#" class="link_button" onclick="lens_subdiv_2();return false;">reveals</a> that we&rsquo;re not done yet. To focus all the rays we need to replicate that smooth shape across <em>all</em> possible directions – we need rotational symmetry:</p>
  251. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_rotational"></div>
  252. <p>We&rsquo;ve created a <em>convex</em> <a href="https://en.wikipedia.org/wiki/Thin_lens">thin lens</a>. This lens is idealized, in the later part of the article we&rsquo;ll discuss how real lenses aren&rsquo;t as perfect, but for now it will serve us very well. Let&rsquo;s see what happens to the focus point when we change the position of the <span class="lens_red">red</span> source:</p>
  253. <div class="drawer_container lens_long_drawer medium_drawer move_cursor" id="lens_rotational_focal"></div>
  254. <div class="lens_red" id="lens_rotational_focal_sl0"></div>
  255. <p>When the source is positioned <a href="#" class="link_button" onclick="lens_inf();return false;">very far away</a> the incoming rays become parallel and after passing through lens they converge at a certain distance away from the center. That distance is known as <a href="https://en.wikipedia.org/wiki/Focal_length"><em>focal length</em></a>.</p>
  256. <p>The previous demonstration also shows two more general distances: <strong>s<sub>o</sub></strong> which is the distance between the <strong>o</strong>bject, or source, and the lens, as well as <strong>s<sub>i</sub></strong> which is the distance between the <strong>i</strong>mage and the lens. These two values and the focal length <strong>f</strong> are related by the <a href="https://en.wikipedia.org/wiki/Thin_lens#Image_formation"><em>thin lens equation</em></a>:</p>
  257. <div class="equation">
  258. <span class="equation_frac"><span>1</span>
  259. <span class="equation_div_symbol">/</span>
  260. <span class="lns_div_bottom">s<sub>o</sub></span>
  261. </span>
  262. +
  263. <span class="equation_frac"><span>1</span>
  264. <span class="equation_div_symbol">/</span>
  265. <span class="lns_div_bottom">s<sub>i</sub></span>
  266. </span>
  267. =
  268. <span class="equation_frac"><span>1</span>
  269. <span class="equation_div_symbol">/</span>
  270. <span class="lns_div_bottom">f</span>
  271. </span>
  272. </div>
  273. <p>Focal length of a lens depends on both the <span class="lens_black">index of refraction</span> of the material from which the lens is made and its <span class="lens_blue">shape</span>:</p>
  274. <div class="drawer_container lens_long_drawer medium_drawer move_cursor" id="lens_focal_length"></div>
  275. <div class="lens_black" id="lens_focal_length_sl1"></div>
  276. <div class="lens_blue" id="lens_focal_length_sl0"></div>
  277. <p>Now that we understand how a simple convex lens works we&rsquo;re ready to mount it into the hole of our camera. We will still control the <span class="lens_yellow">distance</span> between the sensor and the lens, but instead of controlling the diameter of the lens we&rsquo;ll instead control its <span class="lens_blue">focal length</span>:</p>
  278. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_box_lens"></div>
  279. <div class="lens_blue" id="lens_box_lens_sl0"></div>
  280. <div class="lens_yellow" id="lens_box_lens_sl1"></div>
  281. <p>When you look at the lens <a href="#" class="link_button" onclick="lens_camera_lens();return false;">from the side</a> you may observe how the <span class="lens_blue">focal length</span> change is tied to the shape of the lens. Let&rsquo;s see how this new camera works in action:</p>
  282. <div class="drawer_container double_drawer" id="lens_basic"></div>
  283. <div class="lens_blue" id="lens_basic_sl0"></div>
  284. <div class="lens_yellow" id="lens_basic_sl1"></div>
  285. <p>Once again, a lot of things are going on here! Firstly, let&rsquo;s try to understand how the image is formed in the first place. The demonstration below shows paths of rays from two separate points in the scene. After going through the lens they end up hitting the sensor:</p>
  286. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_lens_solid_angle"></div>
  287. <div class="lens_blue" id="lens_lens_solid_angle_sl0"></div>
  288. <div class="lens_yellow" id="lens_lens_solid_angle_sl1"></div>
  289. <p>Naturally, this process happens for <em>every</em> single point in the scene which creates the final image. Similarly to a pinhole a convex lens creates an inverted picture – I&rsquo;m still correcting for this by showing you a rotated photograph.</p>
  290. <p>Secondly, notice that the distance between the lens and the sensor still controls the field of view. As a reminder, the focal length of a lens simply defines the distance from the lens at which the rays coming from infinity converge. To achieve a sharp image, the sensor has to be placed at the location where the rays focus and <em>that&rsquo;s</em> what&rsquo;s causing the field of view to change.</p>
  291. <p>In the demonstration below I&rsquo;ve visualized how rays from a very far object focus through a lens of adjustable <span class="lens_blue">focal length</span>, notice that to obtain a sharp image we must change the <span class="lens_yellow">distance</span> between the lens and the sensor which in turn causes the field of view to change:</p>
  292. <div class="drawer_container double_drawer" id="lens_field2"></div>
  293. <div class="lens_blue" id="lens_field2_sl1"></div>
  294. <div class="lens_yellow" id="lens_field2_sl0"></div>
  295. <p>If we want to change the object on which a camera with a lens of a fixed focal length is focused, we have to move the image plane closer or further away from the lens which affects the angle of view. This effect is called <a href="https://en.wikipedia.org/wiki/Breathing_(lens)">focus breathing</a>:</p>
  296. <div class="drawer_container double_drawer" id="lens_focus_demo2"></div>
  297. <div class="lens_yellow" id="lens_focus_demo2_sl0"></div>
  298. <p>A lens with a fixed focal length like the one above is often called a <em>prime</em> lens, while lenses with adjustable focal length are called <em>zoom</em> lenses. While the lenses in our eyes do dynamically adjust their focal lengths by changing their shape, rigid glass can&rsquo;t do that so zoom lenses use a system of multiple glass elements that change their relative position to achieve this effect.</p>
  299. <p>In the simulation above notice the difference in sharpness between the red and green spheres. To understand why this happens let&rsquo;s analyze the rays emitted from two points on the surface of the spheres. In the demonstration below the right side shows the light seen by the sensor <em>just</em> from the two marked points on the spheres:</p>
  300. <div class="drawer_container double_drawer" id="lens_lens_solid_angle2"></div>
  301. <div class="lens_yellow" id="lens_lens_solid_angle2_sl0"></div>
  302. <p>The light from the point in focus converges to a point, while the light from an out-of-focus point spreads onto a circle. For larger objects the multitude of overlapping out-of-focus circles creates a smooth blur called
  303. <a href="https://en.wikipedia.org/wiki/Bokeh"><em>bokeh</em></a>. With tiny and bright light sources that circle itself is often visible, you may have seen effects like the one in the demonstration below in some photographs captured in darker environments:</p>
  304. <p><br></p>
  305. <div class="dark_light_bg_grad_top"></div>
  306. <div class="dark_light_bg"><div class="bg_content">
  307. <p><br></p>
  308. <div class="drawer_container double_drawer" id="lens_bokeh"></div>
  309. <br>
  310. <div class="lens_yellow" id="lens_bokeh_sl0"></div>
  311. <p>
  312. </div>
  313. </div>
  314. <div class="dark_light_bg_grad_bottom"></div>
  315. <p><br></p></p>
  316. <p>Notice that the circular shape is visible for lights both in front of and behind the focused distance. As the object is positioned closer or further away from the lens the image plane &ldquo;slices&rdquo; the cone of light at different location:</p>
  317. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_cone_slice"></div>
  318. <div class="lens_red" id="lens_cone_slice_sl0"></div>
  319. <p>That circular spot is called a <a href="https://en.wikipedia.org/wiki/Circle_of_confusion"><em>circle of confusion</em></a>. While in many circumstances the blurriness of the background or the foreground looks very appealing, it would be very useful to control how much blur there is.</p>
  320. <p>Unfortunately, we don&rsquo;t have total freedom here – we still want the primary photographed object to remain in focus so its light has to converge to a point. We just want to change the size of the circle of out-of-focus objects without moving the central point. We can accomplish that by changing the <em>angle</em> of the cone of light:</p>
  321. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_cone_angle"></div>
  322. <div id="lens_cone_angle_sl0"></div>
  323. <p>There are two methods we can use to modify that angle. Firstly, we can change the focal length of the lens – you may recall that with longer focal lengths the cone of light also gets longer. However, changing the focal length and keeping the primary object in focus requires moving the image plane which in turn changes how the picture is framed.</p>
  324. <p>The alternative way of reducing the angle of the cone of light is to simply ignore some of the &ldquo;outer&rdquo; rays. We can achieve that by introducing a stop with a hole in the path of light:</p>
  325. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_cone_aperture"></div>
  326. <div class="lens_black" id="lens_cone_aperture_sl0"></div>
  327. <p>This hole is called an <a href="https://en.wikipedia.org/wiki/Aperture"><em>aperture</em></a>. In fact, even the hole in which the lens is mounted is an aperture of some sort, but what we&rsquo;re introducing is an <em>adjustable</em> aperture:</p>
  328. <div class="drawer_container square_drawer small_drawer move_cursor" id="lens_box_aperture"></div>
  329. <div class="lens_black" id="lens_box_aperture_sl0"></div>
  330. <div class="lens_yellow" id="lens_box_aperture_sl1"></div>
  331. <p>Let&rsquo;s try to see how an aperture affects the photographs taken with our camera:</p>
  332. <div class="drawer_container double_drawer" id="lens_focus_demo3"></div>
  333. <div class="lens_black" id="lens_focus_demo3_sl0"></div>
  334. <div class="lens_yellow" id="lens_focus_demo3_sl1"></div>
  335. <p>In real camera lenses an adjustable aperture is often constructed from a set of overlapping blades that constitute an <em>iris</em>. The movement of those blades changes the size of the aperture:</p>
  336. <div class="drawer_container square_drawer" id="lens_blades"></div>
  337. <div id="lens_blades_sl0"></div>
  338. <p>The shape of the aperture also defines the shape of bokeh. This is the reason why bokeh sometimes has a polygonal shape – it&rsquo;s simply the shape of the &ldquo;cone&rdquo; of light after passing through the blades of the aperture. Next time you watch a movie pay a close attention to the shape of out-of-focus highlights, they&rsquo;re often polygonal:</p>
  339. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_cone_hex"></div>
  340. <div id="lens_cone_hex_sl0"></div>
  341. <p>As the aperture diameter decreases, larger and larger areas of the photographed scene remain sharp. The term <a href="https://en.wikipedia.org/wiki/Depth_of_field"><em>depth of field</em></a> is used to define the length of the region over which the objects are acceptably sharp. When describing the depth of field we&rsquo;re trying to conceptually demark those two boundary planes and see how far apart they are from each other.</p>
  342. <p>Let&rsquo;s see the depth of field in action. The <span class="lens_black">black slider</span> controls the aperture, the <span class="lens_blue">blue slider</span> controls the focal length, and the <span class="lens_red">red slider</span> changes the position of the object relative to the camera. The <span style="color:#68C626"><strong>green dot</strong></span> shows the place of perfect focus, while the <span style="color:#3E53A7"><strong>dark blue dots</strong></span> show the limits, or the depth, of positions between which the image of the red light source will be reasonably sharp, as shown by a single outlined pixel on the sensor:</p>
  343. <div class="drawer_container lens_long_drawer medium_drawer move_cursor" id="lens_cone_dof"></div>
  344. <div class="lens_black" id="lens_cone_dof_sl0"></div>
  345. <div class="lens_blue" id="lens_cone_dof_sl1"></div>
  346. <div class="lens_red" id="lens_cone_dof_sl2"></div>
  347. <p>Notice that <a href="#" class="link_button" onclick="lens_dof_0();return false;">the larger</a> the <span class="lens_black">diameter of aperture</span> and <a href="#" class="link_button" onclick="lens_dof_1();return false;">the shorter</a> the <span class="lens_blue">focal length</span> the shorter the distance between the <span style="color:#3E53A7"><strong>dark blue dots</strong></span> and thus the <em>shallower</em> the depth of field becomes. If you recall our discussion of sharpness this demonstration should make it easier to understand why reducing the angle of the cone <em>increases</em> the depth of field.</p>
  348. <p>If you don&rsquo;t have perfect vision you may have noticed that squinting your eyes make you see things a little better. Your eyelids covering some part of your iris simply act as an aperture that decreases the angle of the cone of light falling into your eyes making things sightly less blurry on your retina.</p>
  349. <p>An interesting observation is that aperture defines the diameter of the base of the captured cone of light that is emitted from the object. Twice as large aperture diameter captures roughly <em>four</em> times more light due to increased <a href="https://ciechanow.ski/lights-and-shadows/#solid-angles">solid angle</a>. In practice, the actual size of the aperture as seen from the point of view of the scene, or the <a href="https://en.wikipedia.org/wiki/Entrance_pupil"><em>entrance pupil</em></a>, depends on all the lenses in front of it as the shaped glass may scale the perceived size of the aperture.</p>
  350. <p>On the other hand, when a lens is focused correctly, the focal length defines how large a source object is in the picture. By doubling the focal length we double the width <em>and</em> the height of the object on the sensor thus increasing the area by the factor of four. The light from the source is more spread out and each individual pixel receives less light.</p>
  351. <p>The total amount of light hitting each pixel is proportional to the <em>ratio</em> between the focal length <strong>f</strong> and the diameter of the entrance pupil <strong>D</strong>. This ratio is known as the <a href="https://en.wikipedia.org/wiki/F-number"><em>f-number</em></a>:</p>
  352. <div class="equation">
  353. <span class="equation_frac">N</span> = <span class="equation_frac"><span>f</span>
  354. <span class="equation_div_symbol">/</span>
  355. <span class="lns_div_bottom">D</span>
  356. </span>
  357. </div>
  358. <p>A lens with a focal length of 50 mm and the entrance pupil of 25 mm would have <strong>N</strong> equal to 2 and the <em>f</em>-number would be known as <em>f</em>/2. Since the amount of light getting to each pixel of the sensor increases with the diameter of the aperture and decreases with the focal length, the <em>f</em>-number controls the brightness of the projected image.</p>
  359. <p>The <em>f</em>-number with which commercial lenses are marked usually defines the maximum aperture a lens can achieve and the smaller the <em>f</em>-number the more light the lens passes through. Bigger amount of incoming light allows reduction of exposure time, so the smaller the <em>f</em>-number the <a href="https://en.wikipedia.org/wiki/Lens_speed"><em>faster</em></a> the lens is. By reducing the size of the aperture we can modify the <em>f</em>-number with which a picture is taken.</p>
  360. <p>The <em>f</em>-numbers are often multiples of 1.4 which is an approximation of <span class="sqrt">2</span>. Scaling the diameter of an adjustable aperture by <span class="sqrt">2</span> scales its <em>area</em> by 2 which is a convenient factor to use. Increasing the <em>f</em>-number by a so-called <a href="https://en.wikipedia.org/wiki/F-number#Stops,_f-stop_conventions,_and_exposure"><em>stop</em></a> halves the amount of received light. The demonstration below shows the relatives sizes of the aperture through which light is being seen:</p>
  361. <p><br></p>
  362. <div class="dark_light_bg_grad_top"></div>
  363. <div class="dark_light_bg"><div class="bg_content">
  364. <p><br></p>
  365. <div class="drawer_container square_drawer" id="lens_f"></div>
  366. <div id="lens_f_seg0"></div>
  367. <p>To maintain the overall brightness of the image when <a href="https://en.wikipedia.org/wiki/Stopping_down">stopping down</a> we&rsquo;d have to either increase the exposure time or the sensitivity of the sensor.</p>
  368. <p><br></p>
  369. <p>
  370. </div>
  371. </div>
  372. <div class="dark_light_bg_grad_bottom"></div>
  373. <p><br></p></p>
  374. <p>While aperture settings let us easily control the depth of field, that change comes at a cost. When the <em>f</em>-number increases and the aperture diameter gets smaller we effectively start approaching a pinhole camera with all its related complications.</p>
  375. <p>In the final part of this article we will discuss the entire spectrum of another class of problems that we&rsquo;ve been conveniently avoiding all this time.</p>
  376. <h1 id="aberrations">Aberrations<a href="https://ciechanow.ski/cameras-and-lenses/#aberrations" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  377. <p>In our examples so far we&rsquo;ve been using a perfect idealized lens that did exactly what we want and in all the demonstrations I&rsquo;ve relied on a certain simplification known as the <a href="https://en.wikipedia.org/wiki/Paraxial_approximation">paraxial approximation</a>. However, the physical world is a bit more complicated.</p>
  378. <p>The most common types of lenses are <em>spherical</em> lenses – their curved surfaces are sections of spheres of different radii. These types of lenses are easier to manufacture, however, they actually don&rsquo;t perfectly converge the rays of incoming light. In the demonstration below you can observe how fuzzy the focus point is for various lens radii:</p>
  379. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_spherical"></div>
  380. <div id="lens_spherical_sl0"></div>
  381. <p>This imperfection is known as <a href="https://en.wikipedia.org/wiki/Spherical_aberration"><em>spherical aberration</em></a>. This specific flaw can be corrected with <a href="https://en.wikipedia.org/wiki/Aspheric_lens"><em>aspheric lenses</em></a>, but unfortunately there are other types of problems that may not be easily solved by a single lens. In general, for monochromatic light there are five primary types of aberrations: <a href="https://en.wikipedia.org/wiki/Spherical_aberration">spherical aberration</a>, <a href="https://en.wikipedia.org/wiki/Coma_(optics)">coma</a>, <a href="https://en.wikipedia.org/wiki/Astigmatism_(optical_systems)">astigmatism</a>, <a href="https://en.wikipedia.org/wiki/Petzval_field_curvature">field curvature</a>, and <a href="https://en.wikipedia.org/wiki/Distortion_(optics)">distortion</a>.</p>
  382. <p>We&rsquo;re still not out of the woods even if we manage to minimize these problems. In normal environments light is very <em>non</em>-monochromatic and nature sets another hurdle into optical system design. Let&rsquo;s quickly go back to the dark environment as we&rsquo;ll be discussing a single beam of white light.</p>
  383. <p><br></p>
  384. <div class="dark_light_bg_grad_top"></div>
  385. <div class="dark_light_bg"><div class="bg_content">
  386. <p><br></p>
  387. <p>Observe what happens to that beam when it hits a piece of glass. You can make the sides non-parallel by using the slider:</p>
  388. <div class="drawer_container lens_long_drawer medium_drawer move_cursor" id="lens_prism"></div>
  389. <div id="lens_prism_sl0"></div>
  390. <p>What we perceive as white light is a combination of lights of different wavelengths. In fact, the index of refraction of materials <em>depends</em> on the wavelength of the light. This phenomena called <a href="https://en.wikipedia.org/wiki/Dispersion_(optics)"><em>dispersion</em></a> splits what seems to be a uniform beam of white light into a fan of color bands. The very same mechanism that we see here is also responsible for a rainbow.</p>
  391. <p>In a lens this causes different wavelengths of light to focus at different offsets – the effect known as <a href="https://en.wikipedia.org/wiki/Chromatic_aberration"><em>chromatic aberration</em></a>. We can easily visualize the <em>axial</em> chromatic aberration even on a lens with spherical aberration fixed. I&rsquo;ll only use red, green, and blue dispersed rays to make things less crowded, but remember that other colors of the spectrum are present in between. Using the slider you can control the amount of dispersion the lens material introduces:</p>
  392. <div class="drawer_container lens_very_long_drawer medium_drawer move_cursor" id="lens_chromatic"></div>
  393. <div id="lens_chromatic_sl0"></div>
  394. <p>Chromatic aberration may be corrected with an <a href="https://en.wikipedia.org/wiki/Achromatic_lens">achromatic lens</a>, usually in the form of a <a href="https://en.wikipedia.org/wiki/Doublet_(lens)">doublet</a> with two different types of glass fused together.</p>
  395. <p><br></p>
  396. </div>
  397. </div>
  398. <div class="dark_light_bg_grad_bottom"></div>
  399. <p><br></p>
  400. <p>To minimize the impact of the aberrations, camera lenses use more than one optical element on their pathways. In this article I&rsquo;ve only shown you simple lens systems, but a high-end camera lens may consist of <a href="https://en.wikipedia.org/wiki/File:Objective_Zeiss_Cut.jpg">a lot of elements</a> that were carefully designed to balance the optical performance, weight, and cost.</p>
  401. <p>While we, in our world of computer simulations on this website, can maintain the illusion of simple and perfect systems devoid of aberrations, <a href="https://en.wikipedia.org/wiki/Vignetting">vignetting</a>, and <a href="https://en.wikipedia.org/wiki/Lens_flare">lens flares</a>, real cameras and lenses have to deal with all these problems to make the final pictures look good.</p>
  402. <h1 id="further-watching-and-reading">Further Watching and Reading<a href="https://ciechanow.ski/cameras-and-lenses/#further-watching-and-reading" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  403. <p>Over on YouTube <a href="https://www.youtube.com/channel/UCSFAYalJ2Q7Tm_WmLgetmeg">Filmmaker IQ channel</a> has a lot of great content related to lenses and movie making. Two videos especially fitting here are <a href="https://www.youtube.com/watch?v=1YIvvXxsR5Y">The History and Science of Lenses</a> and <a href="https://www.youtube.com/watch?v=lte9pa3RtUk">Focusing on Depth of Field and Lens Equivalents</a>.</p>
  404. <p><a href="https://www.youtube.com/watch?v=q1n2DR6H7mk">What Makes Cinema Lenses So Special!?</a> on <a href="https://www.youtube.com/channel/UCNJe8uQhM2G4jJFRWiM89Wg">Potato Jet channel</a> is a great interview with Art Adams from <a href="https://www.arri.com/en/">ARRI</a>. The video goes over many interesting details of high-end cinema lens design, for example, how the lenses <a href="https://youtu.be/q1n2DR6H7mk?t=370">compensate for focus breathing</a>, or how much attention is paid to the <a href="https://youtu.be/q1n2DR6H7mk?t=899">quality of bokeh</a>.</p>
  405. <p>For a deeper dive on bokeh itself Jakub Trávník&rsquo;s <a href="https://jtra.cz/stuff/essays/bokeh/index.html">On Bokeh</a> is a great article on the subject. The author explains how aberrations may cause bokeh of non uniform intensity and shows many photographs of real cameras and lenses.</p>
  406. <p>In this article I&rsquo;ve mostly been using <a href="https://en.wikipedia.org/wiki/Geometrical_optics">geometrical optics</a> with some soft touches of electromagnetism. For a more modern look at the nature of light and its interaction with matter I recommend Richard Feynman&rsquo;s <a href="https://en.wikipedia.org/wiki/QED:_The_Strange_Theory_of_Light_and_Matter">QED: The Strange Theory of Light and Matter</a>. The book is written in a very approachable style suited for general audience, but it still lets Feynman&rsquo;s wits and brilliance shine right through.</p>
  407. <h1 id="final-words">Final Words<a href="https://ciechanow.ski/cameras-and-lenses/#final-words" class="hanchor" ariaLabel="Anchor"><img src="https://ciechanow.ski/images/anchor.png" width="16px" height="8px"/></a> </h1>
  408. <p>We’ve barely scratched the surface of optics and camera lens design, but even the most complex systems end up serving the same purpose: to tell light where to go. In some sense optical engineering is all about taming the nature of light.</p>
  409. <p>The simple act of pressing the shutter button in a camera app on a smartphone or on the body of a high-end DSLR is effortless, but it’s at this moment when, through carefully guided rays hitting an array of photodetectors, we immortalize reality by painting with light.</p>
  410. <p></div>
  411. </div></div></div></sub></span></div></p>
  412. </article>
  413. <hr>
  414. <footer>
  415. <p>
  416. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  417. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  418. </svg> Accueil</a> •
  419. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  420. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-rss2"></use>
  421. </svg> RSS</a> •
  422. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  423. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-user-tie"></use>
  424. </svg> Pro</a> •
  425. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  426. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-mail"></use>
  427. </svg> Email</a> •
  428. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  429. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-hammer2"></use>
  430. </svg> Légal</abbr>
  431. </p>
  432. <template id="theme-selector">
  433. <form>
  434. <fieldset>
  435. <legend><svg class="icon icon-brightness-contrast">
  436. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-brightness-contrast"></use>
  437. </svg> Thème</legend>
  438. <label>
  439. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  440. </label>
  441. <label>
  442. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  443. </label>
  444. <label>
  445. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  446. </label>
  447. </fieldset>
  448. </form>
  449. </template>
  450. </footer>
  451. <script>
  452. function loadThemeForm(templateName) {
  453. const themeSelectorTemplate = document.querySelector(templateName)
  454. const form = themeSelectorTemplate.content.firstElementChild
  455. themeSelectorTemplate.replaceWith(form)
  456. form.addEventListener('change', (e) => {
  457. const chosenColorScheme = e.target.value
  458. localStorage.setItem('theme', chosenColorScheme)
  459. toggleTheme(chosenColorScheme)
  460. })
  461. const selectedTheme = localStorage.getItem('theme')
  462. if (selectedTheme && selectedTheme !== 'undefined') {
  463. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  464. }
  465. }
  466. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  467. window.addEventListener('load', () => {
  468. let hasDarkRules = false
  469. for (const styleSheet of Array.from(document.styleSheets)) {
  470. let mediaRules = []
  471. for (const cssRule of styleSheet.cssRules) {
  472. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  473. continue
  474. }
  475. // WARNING: Safari does not have/supports `conditionText`.
  476. if (cssRule.conditionText) {
  477. if (cssRule.conditionText !== prefersColorSchemeDark) {
  478. continue
  479. }
  480. } else {
  481. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  482. continue
  483. }
  484. }
  485. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  486. }
  487. // WARNING: do not try to insert a Rule to a styleSheet you are
  488. // currently iterating on, otherwise the browser will be stuck
  489. // in a infinite loop…
  490. for (const mediaRule of mediaRules) {
  491. styleSheet.insertRule(mediaRule.cssText)
  492. hasDarkRules = true
  493. }
  494. }
  495. if (hasDarkRules) {
  496. loadThemeForm('#theme-selector')
  497. }
  498. })
  499. </script>
  500. </body>
  501. </html>