http://electronics.howstuffworks.com/digital-camera.htm How Digital Cameras Work by Tracy V. Wilson, K. Nice and G. Gurevich 1. Introduction to How Digital Cameras Work In the past twenty years, most of the major technological breakthroughs in consumer electronics have really been part of one larger breakthrough. When you get down to it, CDs, DVDs, HDTV, MP3s and DVRs are all built around the same basic process: converting conventional analog information (represented by a fluctuating wave) into digital information (represented by ones and zeros, or bits). This fundamental shift in technology totally changed how we handle visual and audio information -- it completely redefined what is possible. The digital camera is one of the most remarkable instances of this shift because it is so truly different from its predecessor. Conventional cameras depend entirely on chemical and mechanical processes -- you don't even need electricity to operate them. On the other hand, all digital cameras have a built-in computer, and all of them record images electronically. The new approach has been enormously successful. Since film still provides better picture quality, digital cameras have not completely replaced conventional cameras. But, as digital imaging technology has improved, digital cameras have rapidly become more popular. In this article, we'll find out exactly what's going on inside these amazing digital-age devices. Understanding the Basics Let's say you want to take a picture and e-mail it to a friend. To do this, you need the image to be represented in the language that computers recognize -- bits and bytes. Essentially, a digital image is just a long string of 1s and 0s that represent all the tiny colored dots -- or pixels -- that collectively make up the image. (For information on sampling and digital representations of data, see this explanation of the digitization of sound waves. Digitizing light waves works in a similar way.) If you want to get a picture into this form, you have two options: You can take a photograph using a conventional film camera, process the film chemically, print it onto photographic paper and then use a digital scanner to sample the print (record the pattern of light as a series of pixel values). You can directly sample the original light that bounces off your subject, immediately breaking that light pattern down into a series of pixel values -- in other words, you can use a digital camera. At its most basic level, this is all there is to a digital camera. Just like a conventional camera, it has a series of lenses that focus light to create an image of a scene. But instead of focusing this light onto a piece of film, it focuses it onto a semiconductor device that records light electronically. A computer then breaks this electronic information down into digital data. All the fun and interesting features of digital cameras come as a direct result of this process. In the next few sections, we'll find out exactly how the camera does all this. 2. A Filmless Camera Instead of film, a digital camera has a sensor that converts light into electrical charges. The image sensor employed by most digital cameras is a charge coupled device (CCD). Some cameras use complementary metal oxide semiconductor (CMOS) technology instead. Both CCD and CMOS image sensors convert light into electrons. If you've read How Solar Cells Work, you already understand one of the pieces of technology used to perform the conversion. A simplified way to think about these sensors is to think of a 2-D array of thousands or millions of tiny solar cells. A CMOS image sensor Once the sensor converts the light into electrons, it reads the value (accumulated charge) of each cell in the image. This is where the differences between the two main sensor types kick in: A CCD transports the charge across the chip and reads it at one corner of the array. An analog-to-digital converter (ADC) then turns each pixel's value into a digital value by measuring the amount of charge at each photosite and converting that measurement to binary form. CMOS devices use several transistors at each pixel to amplify and move the charge using more traditional wires. The CMOS signal is digital, so it needs no ADC. Differences between the two types of sensors lead to a number of pros and cons: CCD sensors create high-quality, low-noise images. CMOS sensors are generally more susceptible to noise. Because each pixel on a CMOS sensor has several transistors located next to it, the light sensitivity of a CMOS chip is lower. Many of the photons hit the transistors instead of the photodiode. CMOS sensors traditionally consume little power. CCDs, on the other hand, use a process that Photo courtesy DALSA A CCD sensor consumes lots of power. CCDs consume as much as 100 times more power than an equivalent CMOS sensor. CCD sensors have been mass produced for a longer period of time, so they are more mature. They tend to have higher quality pixels, and more of them. Although numerous differences exist between the two sensors, they both play the same role in the camera -- they turn light into electricity. For the purpose of understanding how a digital camera works, you can think of them as nearly identical devices. Digital Camera Resolution The amount of detail that the camera can capture is called the resolution, and it is measured in pixels. The more pixels a camera has, the more detail it can capture and the larger pictures can be without becoming blurry or "grainy." Some typical resolutions include: 256x256 - Found on very cheap cameras, this resolution is so low that the picture quality is almost always unacceptable. This is 65,000 total pixels. 640x480 - This is the low end on most "real" cameras. This resolution is ideal for e-mailing pictures or posting pictures on a Web site. 1216x912 - This is a "megapixel" image size -- 1,109,000 total pixels -- good for printing pictures. 1600x1200 - With almost 2 million total pixels, this is "high resolution." You can print a 4x5 inch print taken at this resolution with the same quality that you would get from a photo lab. 2240x1680 - Found on 4 megapixel cameras -- the current standard -- this allows even larger printed photos, with good quality for prints up to 16x20 inches. 4064x2704 - A top-of-the-line digital camera with 11.1 megapixels takes pictures at this resolution. At this setting, you can create 13.5x9 inch prints with no loss of picture quality. Photo courtesy Morguefile The size of an image taken at different resolutions High-end consumer cameras can capture over 12 million pixels. Some professional cameras support over 16 million pixels, or 20 million pixels for large-format cameras. For comparison, Hewlett Packard estimates that the quality of 35mm film is about 20 million pixels [ref]. Next, we'll look at how the camera adds color to these images. How Many Pixels? You may have noticed that the number of pixels and the maximum resolution don't quite compute. For example, a 2.1-megapixel camera can produce images with a resolution of 1600x1200, or 1,920,000 pixels. But "2.1 megapixel" means there should be at least 2,100,000 pixels. This isn't an error from rounding off or binary mathematical trickery. There is a real discrepancy between these numbers because the CCD has to include circuitry for the ADC to measure the charge. This circuitry is dyed black so that it doesn't absorb light and distort the image. Capturing Color Unfortunately, each photosite is colorblind. It only keeps track of the total intensity of the light that strikes its surface. In order to get a full color image, most sensors use filtering to look at the light in its three primary colors. Once the camera records all three colors, it combines them to create the full spectrum. Your browser does not support JavaScript or it is disabled. How the three colors mix to form many colors There are several ways of recording the three colors in a digital camera. The highest quality cameras use three separate sensors, each with a different filter. A beam splitter directs light to the different sensors. Think of the light entering the camera as water flowing through a pipe. Using a beam splitter would be like dividing an identical amount of water into three different pipes. Each sensor gets an identical look at the image; but because of the filters, each sensor only responds to one of the primary colors. How the original (left) image is split in a beam splitter The advantage of this method is that the camera records each of the three colors at each pixel location. Unfortunately, cameras that use this method tend to be bulky and expensive. Another method is to rotate a series of red, blue and green filters in front of a single sensor. The sensor records three separate images in rapid succession. This method also provides information on all three colors at each pixel location; but since the three images aren't taken at precisely the same moment, both the camera and the target of the photo must remain stationary for all three readings. This isn't practical for candid photography or handheld cameras. Both of these methods work well for professional studio cameras, but they're not necessarily practical for casual snapshots. Next, we'll look at filtering methods that are more suited to small, efficient cameras. More on Capturing Color A more economical and practical way to record the primary colors is to permanently place a filter called a color filter array over each individual photosite. By breaking up the sensor into a variety of red, blue and green pixels, it is possible to get enough information in the general vicinity of each sensor to make very accurate guesses about the true color at that location. This process of looking at the other pixels in the neighborhood of a sensor and making an educated guess is called interpolation. The most common pattern of filters is the Bayer filter pattern. This pattern alternates a row of red and green filters with a row of blue and green filters. The pixels are not evenly divided -- there are as many green pixels as there are blue and red combined. This is because the human eye is not equally sensitive to all three colors. It's necessary to include more information from the green pixels in order to create an image that the eye will perceive as a "true color." The advantages of this method are that only one sensor is required, and all the color information (red, green and blue) is recorded at the same moment. That means the camera can be smaller, cheaper, and useful in a wider variety of situations. The raw output from a sensor with a Bayer filter is a mosaic of red, green and blue pixels of different intensity. Digital cameras use specialized demosaicing algorithms to convert this mosaic into an equally sized mosaic of true colors. The key is that each colored pixel can be used more than once. The true color of a single pixel can be determined by averaging the values from the closest surrounding pixels. Some single-sensor cameras use alternatives to the Bayer filter pattern. X3 technology, for example, embeds red, green and blue photodetectors in silicon. Some of the more advanced cameras subtract values using the typesetting colors cyan, yellow, green and magenta instead of blending red, green and blue. There is even a method that uses two sensors. However, most consumer cameras on the market today use a single sensor with alternating rows of green/red and green/blue filters. Exposure and Focus Just as with film, a digital camera has to control the amount of light that reaches the sensor. The two components it uses to do this, the aperture and shutter speed, are also present on conventional cameras. Aperture: The size of the opening in the camera. The aperture is automatic in most digital cameras, but some allow manual adjustment to give professionals and hobbyists more control over the final image. Shutter speed: The amount of time that light can pass through the aperture. Unlike film, the light sensor in a digital camera can be reset electronically, so digital cameras have a digital shutter rather than a mechanical shutter. These two aspects work together to capture the amount of light needed to make a good image. In photographic terms, they set the exposure of the sensor. You can learn more about a camera's aperture and shutter speed in How Cameras Work. In addition to controlling the amount of light, the camera has to adjust the lenses to control how the light is focused on the sensor. In general, the lenses on digital cameras are very similar to conventional camera lenses -- some digital cameras can even use conventional lenses. Most use automatic focusing techniques, which you can learn more about in the article How Autofocus Cameras Work. The focal length, however, is one important difference between the lens of a digital camera and the lens of a 35mm camera. The focal length is the distance between the lens and the surface of the sensor. Sensors from different manufacturers vary widely in size, but in general they're smaller than a piece of 35mm film. In order to project the image onto a smaller sensor, the focal length is shortened by the same proportion. For additional information on sensor sizes and comparisons to 35mm film, you can visit the Photo.net Web site. Focal length also determines the magnification, or zoom, when you look through the camera. In 35mm cameras, a 50mm lens gives a natural view of the subject. Increasing the focal length increases the magnification, and objects appear to get closer. The reverse happens when decreasing the focal length. A zoom lens is any lens that has an adjustable focal length, and digital cameras can have optical or digital zoom -- some have both. Some cameras also have macro focusing capability, meaning that the camera can take pictures from very close to the subject. Digital cameras have one of four types of lenses: Fixed-focus, fixed-zoom lenses - These are the kinds of lenses on disposable and inexpensive film cameras -- inexpensive and great for snapshots, but fairly limited. Optical-zoom lenses with automatic focus - Similar to the lens on a video camcorder, these have "wide" and "telephoto" options and automatic focus. The camera may or may not support manual focus. These actually change the focal length of the lens rather than just magnifying the information that hits the sensor. Digital-zoom lenses - With digital zoom, the camera takes pixels from the center of the image sensor and interpolates them to make a full-sized image. Depending on the resolution of the image and the sensor, this approach may create a grainy or fuzzy image. You can manually do the same thing with image processing software -- simply snap a picture, cut out the center and magnify it. Replaceable lens systems - These are similar to the replaceable lenses on a 35mm camera. Some digital cameras can use 35mm camera lenses. Next, we'll learn about how the camera stores pictures and transfers them to a computer. Storing Digital Photos Most digital cameras have an LCD screen, so you can view your picture right away. This is one of the great advantages of a digital camera -- you get immediate feedback on what you capture. Of course, viewing the image on your camera would lose its charm if that's all you could do. You want to be able to load the picture into your computer or send it directly to a printer. There are several ways to do this. Early generations of digital cameras had fixed storage inside the camera. You needed to connect the camera directly to a computer with cables to transfer the images. Although most of today's cameras are capable of connecting through serial, parallel, SCSI, USB or FireWire connections, they usually also use some sort of removable storage device. Digital cameras use a number of storage systems. These Photo courtesy HSW Shopper are like reusable, digital film, and they use a caddy or A CompactFlash card card reader to transfer the data to a computer. Many involve fixed or removable flash memory. Digital camera manufacturers often develop their own proprietary flash memory devices, including SmartMedia cards, CompactFlash cards and Memory Sticks. Some other removable storage devices include: Floppy disks Hard disks, or microdrives Writeable CDs and DVDs No matter what type of storage they use, all digital cameras need lots of room for pictures. They usually store images in one of two formats -- TIFF, which is uncompressed, and JPEG, which is compressed, but some use RAW format. Most cameras use the JPEG file format for storing pictures, and they sometimes offer quality settings (such as medium or high). The following chart will give you an idea of the file sizes you might expect with different picture sizes. TIFF JPEG JPEG (uncompressed) (high quality) (medium quality) 640x480 1.0 MB 300 KB 90 KB 800x600 1.5 MB 500 KB 130 KB Image Size 1024x768 2.5 MB 800 KB 200 KB 1600x1200 6.0 MB 1.7 MB 420 KB To make the most of their storage space, almost all digital cameras use some sort of data compression to make the files smaller. Two features of digital images make compression possible. One is repetition. The other is irrelevancy. Imagine that throughout a given photo, certain patterns develop in the colors. For example, if a blue sky takes up 30 percent of the photograph, you can be certain that some shades of blue are going to be repeated over and over again. When compression routines take advantage of patterns that repeat, there is no loss of information and the image can be reconstructed exactly as it was recorded. Unfortunately, this doesn't reduce files any more than 50 percent, and sometimes it doesn't even come close to that level. Irrelevancy is a trickier issue. A digital camera records more information than the human eye can easily detect. Some compression routines take advantage of this fact to throw away some of the more meaningless data. Next, we'll tie it all together and see how a digital camera takes a picture. Summary It takes several steps for a digital camera to take a picture. Here's a review of what happens in a CCD camera, from beginning to end: You aim the camera at the subject and adjust the optical zoom to get closer or farther away. You press lightly on the shutter release. The camera automatically focuses on the subject and takes a reading of the available light. The camera sets the aperture and shutter speed for optimal exposure. You press the shutter release all the way. The camera resets the CCD and exposes it to the light, building up an electrical charge, until the shutter closes. The ADC measures the charge and creates a digital signal that represents the values of the charge at each pixel. A processor interpolates the data from the different pixels to create natural color. On many cameras, it is possible to see the output on the LCD at this stage. A processor may perform a preset level of compression on the data. The information is stored in some form of memory device (probably a Flash memory card). For more information on digital cameras and related topics, check out the links on the following page. Why are there so many different image formats on the Web? http://www.howstuffworks.com/question408.htm Image Resolution, size, and compression: What does it really mean? http://www.howstuffworks.com/framed.htm?parent=digitalcamera.htm&url=http://www.microscope-microscope.org/imaging/image-resolution.htm Image formats on the Web http://www.howstuffworks.com/question408.htm The two most common by far are GIF and JPEG files. Both of these formats encode static (as opposed to animated) bitmap images. In a bitmap image, the image file has to define the exact color of every pixel in the image. For example, imagine a typical bitmap on the web that is 400 by 400 pixels. To define this image, you would need 24 bits per pixel for 160,000 pixels, or 480,000 bytes. That would be a huge image file, so both the GIF and JPG formats compress the image in different ways. In a GIF image, the number of colors is reduced to 256 and then "runs" of same-color pixels are encoded in a color+numberOfPixels format. For example, if there are 100 pixels on a line with the color 41, the image file stores the color (41) and the length of the run (100). This makes a GIF file great for storing drawings that have lots of same-color pixels. Why are my digital photograph files so huge while photos on other Web sites are much smaller? If you are designing a Web site, sending digital photographs as e-mail attachments or trying to pack as many images on a floppy disk as possible, the size of each image is important. What you want to do is shrink the file size to as few bytes as possible without hurting the image quality. Most Web sites that publish photographs use the JPEG (pronounced "jay-peg") format for their images. JPEG is a popular format for two reasons: 1. It has good compression characteristics on photographic data. 2. It lets you adjust the amount of compression. Sites like BBCi and CNN.com adjust the compression ratio to shrink the file size. Most image-handling programs let you tweak the JPEG compression ratio in one way or another. For example, Paint Shop Pro lets you adjust the compression ratio on a scale from 1 to 99, with 1 offering the best image quality and lowest compression ratio and 99 offering the lowest quality and highest compression. The following images give you some sense of the effect that different compression ratios can have on image quality. In all cases, I started with the same 400x336-pixel image. The original JPEG image at 1-percent compression (maximum quality) takes up 152 kilobytes of disk space, so it is not even included. Besides, there is no difference between 1-percent compression and 20-percent compression in terms of image quality, even though the size of the file goes down by a factor of four! JPEG format, 400x336 pixels, 20% compression, 37 kilobytes JPEG format, 400x336 pixels, 40% compression, 25 kilobytes JPEG format, 400x336 pixels, 60% compression, 19 kilobytes JPEG format, 400x336 pixels, 80% compression, 12 kilobytes JPEG format, 400x336 pixels, 90% compression, 7 kilobytes JPEG format, 400x336 pixels, 95% compression, 4 kilobytes When I look at this particular image, I can begin to see minor degradation at 60-percent compression (most visible on the border of the blue shirt). Eighty-percent and 90-percent compression is progressively worse, and 95-percent compression is badly pixelated. Forty- or 50-percent compression is probably a good value for this image, with an image size of 20 to 25 kilobytes. Another way to lower the size of the file is to reduce the image size. For example, here's the same image in a 200x168 format: JPEG format, 200x168 pixels, JPEG format, 200x168 pixels, 40% compression, 12 kilobytes 60% compression, 9 kilobytes This smaller image size reduces the file size by a factor of two! If your scanner is creating 100-kilobyte files, then your scanner is probably producing images in an uncompressed or slightly compressed JPEG format. Using a program like Paint Shop Pro, you can open the image and re-save it at a different compression ratio to shrink the file size significantly.