Keywords: front-page

## Lab: Feature Extraction

[Exercises] [Workspace]

Purpose: The purpose of this lab is to gain experience with feature extraction. The feature of interest for this exercise is the "first invariant moment" which measures the spread of pixels from the cen- troid of an object.

Activities:

1. Label, autocolor and display an existing image.

   1. Select the image $DIP/data/pieces.kdf an display it.

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

   2. Label and the image with the Labeling (mmach) and Display Image operators.

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

   3. In order to better visualize the labeled image, apply an existing color map using the Autocolor operator. You may choose any one of the automatic color maps.

      1. Glyphs:Visualization:Map Display & Manip:Autocolor
      2. Glyphs:Visualization:Non-Interactive Display:Display Image

2. Notice that the labeled objects look somewhat "noisy". Remove this noise by performing a Closing operation (Dilation followed by Erosion).

   1. A Closing operation is performed by using a Dilation operator followed by an Erosion operator prior to Labeling (mmach). Note that both of these operators require a "Struct Element" for the second input. You can generate an 3x3 structuring element using the 3x3 Str.El. operator. Display the results.

      1. Glyphs:MMACH:Dilation and Erosion:Dilation
      2. Glyphs:MMACH:Dilation and Erosion:Erosion
      3. Glyphs:MMACH:Structural Element:3x3 Str.El.

   2. Connect the input data User defined to the input of Dilation.
   3. Connect the output of Dilation to Erosion.
   4. Connect Erosion to Labeling (mmach).
   5. Connect the 3x3 Str.El. to the second input of both Dilation and Erosion.

      Note that you will want to auto color and display the labeled image as well.

3. Calculate the "First Invariant Moment" of each object by using the Shape Analysis operator.

   1. Recall the first invariant moment measures the spread of pixels from the centroid of each object.

      1. Glyphs:Khoros 1:Feature Extraction:Shape Analysis

   2. The labeled image is the first input image parameter to Shape Analysis.

      1. Open the pane and select the "Invariant Moments" toggle.

4. Examine the output from Shape Analysis. There are several outputs from this operators.

   1. To view a readable printout of the feature value for each object, connect the fourth output ("ASCII File" output) to a file viewer.

      1. Glyphs:Input/Output:Information:File Viewer

   2. To view an image outline of each object, connect the second output ("Outline Image") to an Autocolor operator and display the results using Display Image.

      1. Glyphs:Visualization:Map Display & Manip:Autocolor
      2. Glyphs:Visualization:Non-Interactive Display:Display Image

5. Extract a particular feature using the "VIFF Statistics File" output from Shape Analysis and the Extract Operator

   1. The "VIFF Statistics File" is a binary file which contains all the image statistics. This output file always has 61 elements where each element represents a particular feature measured by the operator. If you look at the help page of the Shape Analysis operator, you will see the correspondence between the feature and the position in the element dimension. Note that element position 42 corresponds to the first invariant moment.
   2. Use the Extract operator to extract the first invariant moment.

      1. Glyphs:Data Manip:Size & Region Operators:Extract
      2. Connect the third output of Shape Analysis (VIFF Statistics) to Extract
      3. Open the pane for Extract and set the following parameters:

         For "Specify Region Size"

         Turn off both "Width" and "Height" parameters

         Turn on "Elements" and set the value equal to 1

         For "Specify Region Origin"

         Turn off both "Width" and "Height" parameters

         Turn on "Elements" and set the value equal to 42

         Note that specifying the region origin element size to 42 corresponds to extracting the first invariant moment.

   3. Plot the extracted data to visualize the feature measured from each object.

      1. Glyphs:Visualization:Plot Display:Display 2D Plot
      2. Once the plot is displayed, change the plot type to "Discrete" by selecting the "Options" button.

Exercises

1. The Shape Analysis operator numbers the objects starting from 0. The Labeling (mmach) operator starts from 1. The background is labeled as 0. What can you do so that the plot appears consistent with the labeled image?
2. Repeat the same experiment with another feature.

Khoros Workspace
Execute the visual program c10s1shape.wk