**NOTE: Read build instructions carefully. We will be using CSIL machines for this assignment. **
The purpose of this assignment is to give you some general experience in writing GPU programs using the CUDA programming model.
Contrast enhancement is a common operation in image processing. It’s a useful method for processing scientific images such as X-Ray images or satellite images. And it is also useful to improve detail in photographs that are over or under-exposed.
The goal of this assignment is to develop a contrast enhancement application that uses GPU acceleration.
On this page, the basic ideas and principles of contrast enhancement using histogram modification are given. We start with the simple case, contrast enhancement for grayscale images. Then, we try to apply the similar method to color images. A straightforward C implementation is given as reference, which can be used as your starting point
A simple method to enhance the contrast of a grayscale image is the histogram equalization. The histogram of an digital image represents its tonal distribution. Histogram equalization effectively spreads out the most frequent intensity values, which results in a better distribution on the histogram. This allows for areas of lower local contrast to gain a higher contrast without affecting the global contrast. The following picture shows the effect of the histogram equalization on the image histogram. More details can be found on the wikipedia page: http://en.wikipedia.org/wiki/Histogram_equalization
Here is an example of histogram equalization, the upper image is the original image and the lower one is the result after applying histogram equalization.
Histogram equalization can be performed in the following steps: Calculate the histogram of the input image;
Normally color images are stored in RGB color space. At the first glance it seems simple to apply histogram equalization to a color image: just do it on each channel. However, applying histogram equalization separately on each channel of a RGB will probably destroy the balance of different color components and result in poor image quality. Here an example is given.
A solution to this problem is first convert the image to a color space that has a separate luminance channel, e.g. the HSL/HSV color space , the YUV color space , or the Lab color space, then apply histogram equalization to the luminance or value channel.
Input image
Result of applying histogram equalization on RGB
Result of applying histogram equalization on HSL
ssh [asb9840u-b01.csil.sfu.ca|asb9840u-b02.csil.sfu.ca|asb9840u-b03.csil.sfu.ca] -p 24
# clone assignment
mkdir build
cd build
cmake ../
make
$ ./build/img2gpu in.pgm in.ppm
Running contrast enhancement for gray-scale images.
Image size: 2560 x 1600
Starting CPU processing...
Processing time: 24.169001 (ms)
Starting GPU processing...
Histogram creation processing time: 0.717000 (ms)
Histogram equalization processing time: 0.403000 (ms)
Contrast processing time: 11.353000 (ms)
Running contrast enhancement for color images.
Image size: 2560 x 1600
Starting CPU processing...
HSL processing time: 203.692001 (ms)
YUV processing time: 190.449997 (ms)
Starting GPU processing...
Histogram creation processing time: 0.877000 (ms)
Histogram equalization processing time: 0.382000 (ms)
HSL processing time: 30.670000 (ms)
Histogram creation processing time: 0.892000 (ms)
Histogram equalization processing time: 0.422000 (ms)
YUV processing time: 19.863001 (ms)
# Output files
ls out*
out_hsl.ppm out.pgm out_yuv.ppm
# Reference output files
reference/
# Obtain validation scripts
cd $REPO
cd scripts
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/run.sh"
# Create reference folder
cd $REPO
mkdir reference
cd reference
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/out.pgm"
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/out_hsl.ppm"
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/out_yuv.ppm"
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/gpu_out_grayscale.pgm"
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/gpu_out_hsl.ppm"
wget "https://www2.cs.sfu.ca/~ashriram/Courses/CS431/assets/img/hw6/reference/gpu_out_yuv.ppm"
cd ../
git add reference
git commit -am "Update Reference"
git push
bash scripts/run.sh
# If you see success then results passed, if you see failed then validation failed.