Keywords: front-page

## Lab: Color Table

[Exercises] [Workspace]

Purpose: The purpose of this lab is to experiment with color and colormaps. In this exercise, you will convert a black and white image into a colored image using colormap utilities.

Activities:

1. Experiment with labelling and building an RGB color table.

   1. Read and display the image $DIP/data/unicamp-logo.kdf. Use the User defined and Display Image operators.

      1. Glyphs:Input/Output:Data Files:User defined
      2. Glyphs:Visualization:Non-Interactive Display:Display Image

   2. Swap the background and foreground pixel values by subtracting all pixel values from 255. Use the operator Subtract From. Why is this necessary? This is explained in the "Labeling" lesson in the Image Manipulation Section (lab 10).

      1. Glyphs:Arithmetic:Two Operand Arithmetic:Subtract From

   3. Label the image that you just created using the Labeling (mmach) operator of the MMACH toolbox, with "connectivity" set to 4, and display it with the Display Image operator.

      1. Glyphs:MMACH:Connected Filters:Labeling (mmach)
      2. Glyphs:Visualization:Non-Interactive Display:Display Image

   4. Use the Statistics operator to determine the total number of labeled regions.

      1. Glyphs:Data Manip:Analysis & Information:Statistics
      2. Glyphs:Input/Output:Information:File Viewer

   5. Build an ASCII color table with 3 columns (RGB) and the same number of rows as the number of regions in the labeled image. Choose the color you want for each region. If you wish, you can create this file using an ASCII editor. For convenience, there is an RGB color table for you to use, the file is $DIP/data/unicamp-lut.ascii. You can view this file using the File Viewer.

      1. Glyphs:Input/Output:Data Files:User defined
      2. Glyphs:Input/Output:Information:File Viewer

   6. Convert the "ASCII" color table to a "kdf colormap" using the operator ASCII to Map.

      1. Glyphs:Input/Output:Import Data:ASCII to Map
      2. Open the ASCII to Map and set the proper parameters (Width = 3, Height = 24). Set the data type to "unsigned byte".

   7. Display the color table using the operator Display Palette.

      1. Glyphs:Visualization:Map Display & Manip:Display Palette

2. Explore three ways of representing/displaying the color image.

   1. Using the Display Image operator, input the labeled image and the color map separately.

      1. Glyphs:Visualization:Non-Interactive Display:Display Image
      2. Connect the labeled image (output of Labeling (mmach) Operator) to the first input of Display Image, and connect the colormap (output of ASCII to Map) to the second input (Colormap Image). Verify that although the image is colored, the pixel value under the cursor shows the VALUE data (you may need to resize the window to see all of the position information).

   2. Combine the colormap (map segment) and the labeled logo image into a single data object using the operator Insert Segments. Display the resultant image.

      1. Glyphs:Data Manip:Segment Operators:Insert Segments
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Connect the colormap to "Input 1" of the Insert Segments operator, and connect the output of the Labeling (mmach) operator to "Input 2".
      4. Open the Insert Segments pane and set it up so that the "Map" segment is inserted into the labeled image.
      5. Display the results.

   3. Using the image you just created, map the value data through the color table (map) by using the operator Map Data. Set the data object color attribute to colorspace RGB before dis- playing it. Use the operator Set Attribute.

      1. Glyphs:Data Manip:Map Operators:Map Data
      2. Glyphs:Data Manip:Object Attributes:Set Attribute
      3. Glyphs:Visualization:Non-Interactive Display:Display Image
      4. The only parameter you need to set in the Set Attribute operator is the "Data Object Color Attributes: Colorspace Parameter". Select the "Colorspace" option and set it to "RGB".
      5. Display the resulting image. Note that when you pan around in the image with your cursor, the values of all three elements are now printed.

   4. Print out the header contents of the following data objects:

      Labeled image

      Colortable data

      Labeled image together with the colortable

      Mapped image

      and interpret the contents with respect to the dimensions of the segments "value" and "map". Use the Data Object Info and File Viewer operators.

      1. Glyphs:Input/Output:Information:Data Object Info
      2. Glyphs:Input/Output:Information:File Viewer

Exercises

1. Compare the sizes of the mapped image (output of Map Data) and the labeled image file with the color table (output of Insert Segments).
2. Is it useful to have a color table with only a single column. What are the advantages of using it?

Khoros Workspace
Execute the visual program c4s1logo-color.wk