Keywords: front-page

## Lab: Logarithm Contrast Enhancement/Scaling

[Exercises] [Workspace]

Purpose: The purpose of this lab is to experiment with a technique of image contrast enhancement achieved by first scaling the image and then applying logarithmic functions.

Activities:

1. First demonstrate the scaling problem using a 1D signal. Follow the steps outlined below:

   1. Create a 1D ramp signal of width 100 (Number Cols = 100) and values ranging from 0 to 21. Use the Piecewise Linear operator. Plot the output using Display 2D Plot to verify that the desired ramp signal was generated.

      1. Glyphs:Khoros 1:Generate Data:Piecewise Linear
      2. Glyphs:Visualization:Plot Display:Display 2D Plot

   2. Take the logarithm of the ramp signal and plot it using the operators Logarithm and Display 2D Plot.

      1. Glyphs:Arithmetic:NonLinear Functions:Logarithm
      2. Glyphs:Visualization:Plot Display:Display 2D Plot

   3. Repeat the last step, but first multiply the ramp signal by a factor of 255, using the Multiply operator.

      1. Glyphs:Arithmetic:Two Operand Arithmetic:Multiply
      2. Glyphs:Arithmetic:NonLinear Functions:Logarithm
      3. Glyphs:Visualization:Plot Display:Display 2D Plot

2. Now show the same scaling problem applied to an image, following the steps outlined below:

   1. Use the image $DIP/data/log-enhance-problem.kdf for this experiment. Read and display the image using operators User defined and Display Image. Calculate and plot the histogram of this image using the Histogram and Display 2D Plot operators.

      1. Glyphs:Input/Output:Data Files:User defined
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Glyphs:Data Manip:Histogram Operators:Histogram
      4. Glyphs:Visualization:Plot Display:Display 2D Plot

      The following steps are a repeat of steps B and C from Part 1, but are now applied to an image instead of a signal.

   2. Take the logarithm of the image and display it using the Logarithm and Display Image operators. Calculate the histogram and plot it using the operators Histogram and Display 2D Plot. Since the result of computing the logarithm is floating point, normalize the output between 0 and 255 before calculating the histogram so that you can better see the distribution of pixel values.

      1. Glyphs:Arithmetic:NonLinear Functions:Logarithm
      2. Glyphs:Visualization:Plot Display:Display 2D Plot
      3. Glyphs:Data Manip:Data Conversion:Normalize
      4. Glyphs:Data Manip:Histogram Operators:Histogram
      5. Glyphs:Visualization:Plot Display:Display 2D Plot

   3. Repeat the last step, except first multiply the image by a factor of 255. Use the Multiply operator.

      1. Glyphs:Arithmetic:Two Operand Arithmetic:Multiply
      2. Glyphs:Arithmetic:NonLinear Functions:Logarithm
      3. Glyphs:Visualization:Plot Display:Display 2D Plot
      4. Glyphs:Data Manip:Data Conversion:Normalize
      5. Glyphs:Data Manip:Histogram Operators:Histogram
      6. Glyphs:Visualization:Plot Display:Display 2D Plot

   4. Implement one simple solution to overcome this scaling problem by multiplying by a factor of 50 before taking the logarithm. Apply this technique to both the original $DIP/data/log-enhance-problem.kdf image and the one scaled by 255. Compare the results.

Exercises

1. Can you propose a better way of using a contrast enhancement table that would not have this effect?

Khoros Workspace
Execute the visual program c4s7contrast-log-scaling.wk