header

Lab 12

In this assignment you will add some basic image processing capabilities to your image viewer application. Modify your program from Hmwk 11 as follows:

  1. Implement the setFreqDist function in the imageType class.
  2. Implement the displayFreqDist function in the imageType class.
  3. Implement the adjustBrightness function in the imageType class.
  4. Implement the adjustContrast function in the imageType class.

For more information see the function headers and/or the image processing page.

File Submission

Load your Image project file into Quincy and then open your Hmwk11.cpp file. Save it as Lab12.cpp. Delete Hmwk11.cpp from your project and insert Lab12.cpp. Save your project file. Submit your project file and your Lab12.cpp application as email attachments.

The setFreqDist Function

One of the data members of the imageType class is an array of 256 integers. This array is named "freq" and its purpose is to store the intensity frequency distribution for the current image. The array indexes also serve as intensities and the number stored at a particular index is the number of pixels in the current image that have the corresponding index. For example, the value of freq[100] is the number of pixels in the current image that have an intensity of 100.

The purpose of the setFreqDist function is to set the values in the array for the current image. That is, for each intensity value from 0 to 255, this function counts the number of pixels that have that intensity and stores the result in the corresponding location in the freq array.

This function should be invoked every time an image is read in from memory and any time the current image is modified.

The displayFreqDist Function

This function displays the intensity frequency distribution in a graphics window. This function should be invoked every time the setFreqDist function is invoked.

The adjustBrightness Function

The adjustBrightness function adjusts the brightness of the image. The only thing not discussed on the image processing page is how to auto-adjust the brightness. For this assignment, auto-adjust means that the median brightness of the resulting image should be an intensity level of 128. The corresponding delta value is simply 128 minus the median intensity of the current image. Notice that if the current image is bright (median intensity greater than 128) then delta will be negative and if the current image is dark (median intensity less than 128) then delta will be positive.

The adjustContrast Function

This function adjusts the contrast of the image. When performing an auto-adjustment, the simplest approach is to map the lowest pixel intensity in the image to black and the highest pixel intensity to white. In practice, that may not work because you might have a few stray pixels that are very bright (or very dark) and using those values to set up the mapping function might not improve the image very much. Using the pixel intensities at the 1st (low) and 99th (high) percentiles prevents a few stray pixels from inadvertently leading to a poor result.