Keywords: front-page

## Lab: Histogram Equalization

[Exercises] [Workspace]

Purpose: The purpose of this lab is to experiment with the histogram equalization technique for image contrast enhancement.

Activities:

1. Calculate the histogram of a data set.

   1. Read the image $DIP/data/cathedral.kdf and display it using the operators User defined and Display Image.

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

   2. Determine the histogram of the image and plot it. Use operators Histogram and Display 2D Plot.

      1. Glyphs:Data Manip:Histogram Operators:Histogram
      2. Glyphs:Visualization:Plot Display:Display 2D Plot
      3. View the histogram as a "discrete" plot

   3. Normalize the cumulative histogram (second output of the Histogram operator, "Integrated histogram object") to the desired range of the output image, e.g. 0 to 255, and convert the data type to unsigned byte. Use the Normalize operator. Plot the cumulative histogram using the Display 2D Plot operator.

      1. Glyphs:Data Manip:Data Conversion:Normalize
      2. Glyphs:Visualization:Plot Display:Display 2D Plot

   4. Convert the normalized cumulative histogram to a "Map" segment (color table), using the operator Copy from Value.

      1. Glyphs:Data Manip:Segment Operators:Copy from Value
      2. Open the Copy from Value operator and select the "Map" segment.

2. Use the color table in the three possible ways:

   1. Use the Display Image operator directly.

      1. Glyphs:Visualization:Non-Interactive Display:Display Image

   2. Combine the "Map" segment to the original image file.

      1. Glyphs:Data Manip:Segment Operators:Insert Segments
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Connect the color table to "Input 1" and the original image to "Input 2". Open the Insert Segments operator and set the parameters so that the "Map" segment is transferred.

   3. Map the "Map" segment to the original image.

      1. Glyphs:Data Manip:Map Operators:Map Data
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Use the output from the Insert Segments operator (Step 3-B) as the input to Map Data.

3. Calculate the histogram of the equalized image.

   1. Calculate the histogram of the histogram equalized image (output from Part 3-C) and plot it using the Histogram and Display 2D Plot operators.

      1. Glyphs:Data Manip:Histogram Operators:Histogram
      2. Glyphs:Visualization:Plot Display:Display 2D Plot

   2. Use the operator Equalize to perform the histogram equalization directly. Check if your implementation generates the same results as this operator (look at the resulting image and the histogram of the image). Use the Compare Objects operator to compare the image data and the histograms.

      1. Glyphs:Data Manip:Histogram Operators:Equalize
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Glyphs:Data Manip:Histogram Operators:Histogram
      4. Glyphs:Visualization:Plot Display:Display 2D Plot
      5. Glyphs:Data Manip:Analysis & Information:Compare Objects
      6. Glyphs:Input/Output:Information:File Viewer
      7. Open the Compare Objects pane and unselect the "Silent" option.
      8. Connect the output of Compare Objects to the File Viewer

Exercises

1. Apply this technique only to a selected portion of the image. Use the MASK segment to select the area of interest.
2. One solution to obtain a more uniform histogram in the resultant image is by converting the image to floating point pixels and adding uniform noise ranging from [0, 1] to each pixel. Equalizing this image which has larger number of gray levels will result in a more uniform histogram.

Khoros Workspace
Execute the visual program c4s5equalization.wk