Laboratory: Digital Images and Color
CSC 105 - The Digital Age

In this lab, you'll explore several aspects of images:


To prepare for the exercise:
  • Open a Terminal window
  • You may have a directory named 105 within your home directory, which you created in a previous laboratory session. Use the command ls to determine whether that directory exists. If it does exist, go to the next step. If it does not, create it by entering the following mkdir command in your Terminal command line, as shown below:
      mkdir 105
  • To run a program that will copy some images into that directory, enter (or copy) the following command to your Terminal command line:
  • Move to your 105 directory with the command:
      cd 105
  • Check that the images college-logo.gif, paradise.jpg, rainbow.gif, and water-lilies.jpg exist in your directory:

      ls -l
    In the file listing, the number displayed just left of the file date tells you the number of bytes in each file. How many bytes are in the original pictures college-logo.gif, paradise.jpg, and water-lilies.jpg?

  • While you will be working with copies of images on your account, this page shows the original images.
  • Part I: Exploring Image File Formats

    In this part of the laboratory, you will work with a free open-source image manipulation program (similar to Adobe's Photoshop) called GIMP, which stands for Gnu Image Manipulation Program. You will use GIMP to explore two common image file formats, gif and jpg. (The latter format is also referred to as jpeg).

    Creating jpeg Files from gif Files

    As discussed in class, the JPEG file format can utilize the full range of RGB values. In contrast, although GIF files can include any particular color, they are limited to a maximum number (often 256) of colors total. This is because the GIF format stores colors in a table, and then refers to those colors by their position in the table (i.e., their index position), rather than by the full RGB triple.

    As a practical matter, this means that image processing software such as the GIMP generally can work with images in two color modes: RGB mode, and indexed mode. JPEG images use RGB mode, and GIF images use indexed mode. Thus, in converting an image from the JPEG format to the GIF format (or back), you will need to change image modes.

    1. To open the laurel-leaf logo (a GIF image) in the GIMP, type the command
        gimp college-logo.gif &
      The ampersand & at the end of this line tells Linux to open the GIMP in windows separate from your terminal window, so that your terminal window is still free for you to use.

      The first time you use GIMP, the program needs to set up some directories and files for its processing. To accomplish this, the program will lead you through a series of steps.

      • Throughout the initilization process for GIMP, you can safely accept the default values by just pressing Next or finish or similar options as they are presented.

      The GIMP program will open several windows, including a picture with the image itself. At the top of the frame containing the picture, note that the caption includes the word Indexed to show that a color table is being used.

      • Close GIMP's "Tip of the Day" window (after reading it, if you wish).
    2. To change the mode of the image to full RGB:
    3. To save the picture as a jpeg file:
      1. Right-click on the image, and then select File and Save As. (Be careful to select "Save As", not "Save", because this will allow you to keep both the original gif image and the new jpg image.)
      2. In the "Save Image" dialog box that appears, click on the triangle just left of "Select File Type (By Extension)".
      3. Scroll down the list of file types, and select "JPEG image".
      4. Check that the file name has changed to college-logo.jpg, and click Save.
      5. JPEG allows various quality settings. In general, the better the quality, the larger the file. In the next dialog box that appears, accept the default quality (85), and click Save.
    4. Close the image, either by selecting Close from the File menu, or by clicking on the X in the upper-right corner of the image window. (Do not close GIMP yet.)
    5. In the terminal window, you may see that GIMP has printed some messages, which you can safely ignore. Press Enter in the terminal window to get the usual prompt back.

      Then check that a new image was created with

        ls -l

      How many bytes are there in college-logo.gif? How many bytes in college-logo.jpg?

    6. To open both of the college logo images:
      • Bring the GIMP toolbar window to the front again.
      • Select Open from the File menu.
      • Double-click on college-logo.gif in the dialog box that appears.
      • Open college-logo.jpg in similar fashion.

      (Yes, I realize that we just closed one of these images. It seems to be important that the image be closed and re-opened, after changing its file type, to illustrate the following issue.)

    7. Arrange your windows so that you can see at least part of both images as well as the GIMP toolbar window. Then to get a close-up view of both images:
      • Find an icon on the GIMP toolbar that looks like a magnifying glass, and click on it. Now if you click on either image, it will zoom in.
      • Select one of the points in the laurel leaf logo, and zoom in on it in both images. (Be sure that you are zooming in on each image an equal amount. To do so, it will be useful to observe the icon in the lower-left corner of each image that shows the zoom amount as a percentage.)

      Describe what you see, paying particular attention to the colors that you see, in the close-up view of each image.

    8. Which image format seems to be most suitable for the logo image?
    9. Close both images, but do not close GIMP yet.

    Creating GIF Files from JPEG Files

    Converting an image from JPEG to GIF format with GIMP follows a similar process.
    1. Open the image paradise.jpg in the GIMP.
    2. Now change the color mode of the image to "indexed":
      • Right-click on the image, and select Image, then Mode, and then Indexed.
      • Click OK in the dialog box that appears, to accept the default number of colors (256). This will cause a color table to be created for the image.
      • Note that the caption of the frame now indicates Indexed rather than RGB.
    3. Save the picture as a gif file, following an analogous process as used above for saving in jpeg format.
    4. Close and re-open the file paradise.gif. Then open the original file paradise.jpg as well.
    5. Now take a closer look at each of these pictures, again focusing on the colors they contain in a given region. I suggest looking at some area in the sky or the distant hills. (Again, as you zoom in, be sure to zoom in on each image an equal amount.)

      Describe what you see when zooming in on each image.

    6. Back in your terminal window, check the size of each version of these files. How many bytes does each one occupy?
    7. Which image format seems most appropriate for the "paradise" image?
    8. Do you have a hypothesis about what types of images are most appropriate for each of these two image formats?
    9. Close both of the "paradise" images, but don't close the GIMP yet.

    Part II: Re-Sizing Images

    In this part of the laboratory, you will experiment with scaling images. One reason for doing so is that images taken with modern digital cameras tend to be very large in terms of the numbers of pixels involved. As a result, if we post a full-size image on the web, it can take a very long time for the web page to load in a browser because all those pixels need to be transferred to the user's computer for viewing. Thus, it is preferable to post small versions of your images.
    1. Open the image water-lilies.jpg in the GIMP.
    2. This image is already reasonably small, as you can see by moving your mouse to the far bottom-right corner of the image, and then looking at the pixel coordinates displayed in the bottom-left of the window. Estimate the number of pixels in each row and column of this image.
    3. Now select Scale Image... from the Image menu. In the dialog box that appears, change the width of the image to 600 (pixels per row). When you have done so, press Enter or TAB, and you should see that the height of the image is also automatically changed to maintain the correct "aspect ratio" (ratio of width to height). This will keep the the image from getting distorted.
    4. Click on the Scale button to shrink the image to the specified size.
    5. Finally, save your reduced-size image. (If you would like to keep the original image as well, be sure to use Save As and give your new image a new name.)
    6. Close any images you still have open, but do not close the GIMP.

    Part III: Exploring Image Compression

    In this part of the lab, you'll experiment with the effects of image compression in the JPEG and GIF formats.

    Exploring GIF Compression

    GIF uses a "lossless" compression method, which means the image file stored is smaller, but the resulting displayed image is precisely the same. Here you will look at two images that can indicate a little bit about how GIF represents images.
    1. Open the image rainbow.gif in the GIMP.
    2. From the Image menu, choose Transform and then click Rotate 90 degrees CW. The resulting image should contain vertical, rather than horizontal stripes.
    3. Save the resulting image using Save As under the File menu. Be sure to give it a new name, such as rainbow-vert.gif
    4. How many bytes is the original (horizontally striped) rainbow.gif file? How does this compare to the rotated (vertically striped) GIF file?
    5. Can you hypothesize why there may be such a difference?

      Think about how you might describe this picture to someone so that they might draw it themselves. What if you could only describe the color and how long to draw the color horizontally?

    6. Close any images you have open, but do not close the GIMP.

    Exploring JPEG Compression

    JPEG uses a "lossy" compression algorithm, which makes the image files much smaller, but they can be visibly affected because data is lost in the compression process. In this part you'll explore these effects on image quality and file size.
    1. Open the image water-lilies.jpg in the GIMP.
    2. Choose Save As from the File menu. Give the file a different name, but keep the jpg extension at the end of the file name. Click OK.
    3. A dialog box titled "Save as JPEG" will appear. Check the box labeled "Show Preview in image window". This will allow you to see the result of saving the compressed image without actually saving and reopening it. Position the dialog box and the image so that you can easily change the Quality slider while also viewing most (or all) of the image.
    4. Experiment with the quality slider.
      • How quickly does the file size reported decrease?
      • How much does the file size decrease before the difference in image quality becomes visibly noticeable?
      • How low can you set the Quality before the the image is really drastically altered (e.g., blocky edges, strange colors and "noise")? What is the file size?
      • What does the image look like for extremely low Qualities (e.g. 1-6)?
    5. What can you conclude about the relationship between the compressed file size and visible image quality?
    6. Is it possible for images to be compressed (i.e. a quality less than 100) without visible loss?
    7. Close any images you still have open, and also close the GIMP.
    If we have time at the end of lab, we will talk about how the JPEG and GIF image formats compress images.

    Part IV: Exploring RGB (Red,Green,Blue) Colors

    From the class discussion, you know that colors can be represented by dividing them into their red, green, and blue components. On computers, the intensity of each of these three colors is typically specified on a scale from 0 through 255.

    In this exercise we will use the "Color Chooser" tool provided on the MathLAN systems.

    1. Open a terminal window and type the following command to start the color chooser:
        kcolorchooser &
    2. Find the color chooser in the upper-left portion of the window. Notice that there is a small o on the color pane, indicating the location of the "current" color. Click on the o and drag it around within the color chooser. Notice that as you change the current color, the numeric values for red, green, and blue displayed below the color chooser will change accordingly.
    3. Drag the "current color" o to the top of the color circle. (Tip: You may find it easiest to drag your mouse a little ways above the color chooser. This will position the o exactly on the upper edge of the wheel.)

      Now drag the o across the top of the chooser, and watch how the numeric RGB values change.

      • What RGB values represent turquoise (also called cyan)?
      • What values represent magenta (a strong pink-purple)?
      • What values represent a strong yellow?

    4. Choose a color somewhere on the upper edge of the color chooser, and select that color with the mouse.

      Now turn your attention to the numeric RGB values. One of them should be zero.

      Note the arrows to the right of the RGB values. Use the arrows to increase the value of the RGB component that is zero. What happens to the color as you do this? (Watch the X)

      Return the component (R, G, or B) you changed back to zero.

    5. Now notice the slider to the right of the color chooser. It should have an arrow pointer all the way at the top. This is called the "value" slider.

      Slide the pointer down. What happens to the RGB values as you do this? What is the effect on the color?

    6. Set all of the RGB components to 255. Now try sliding the "value" slider down. What colors are produced when all the RGB values are identical?
    7. Close the color chooser program by clicking the X in the upper corner of the window.

    For those with extra time:

    1. Start the KolourPaint program by typing the following command at the terminal window:
       kolourpaint &
      This opens a window with a canvas in the middle, a toolbar on the left, and a color palette near the bottom.
    2. At the bottom-left of the window is a box with two arrows and overlapping black and white squares. The black square represents the current choice of foreground color (currently black) , while the white square is the background color (currently white). You can double click on either square to bring up the color chooser from the last part of the lab to select your own color to use. Alternatively, you may select a pre-defined color from the palette at the bottom of the window.
    3. Explore the functionality of the various tools on the toolbar. Notice that if you hold the mouse over one of the tools, a brief text description of the tool will appear. You might try each tool in turn: click on it to make it active, test it out by drawing on your canvas.

      Note that some of the tools provide options to modify the to the tool (e.g., wide or narrow paintbrushes, text size and font) at the bottom of the toolbar.

    4. You can save your artwork by selecting Save under the File menu. Select an appropriate file type for your image, give it a name (including an appropriate file extension), and then press OK.
    5. Close KolourPaint by clicking the X in the upper-right corner of he window.
    Created: Henry Walker, January 30, 2004
    Revised: Henry Walker, February 16, 2005
    Marge Coahran, February 9, 2008
    Jerod Weinman, January 1, 2009
    Jerod Weinman, February 8, 2011