Assignment 1

CSE 455

Before you start:

Download the project's files here.

Please read the word document on "Getting started with Qt.docx" to install Qt.

 

Assignment:

For this assignment, you'll be implementing the functionality of the ImgFilter program. The program allows you to load an image and apply various images filters.

In the project, you should only have to update one file "Project1.cpp." The buttons in the UI will call the corresponding functions in "Project1.cpp. " Several of the buttons have already been implemented, including "B/W", "Add noise", "Mean" and "Half size. " The implementations of these buttons are in "Project1.cpp", and should provide helper sample code. Please see these functions to understand how to access the pixels in the image.

What to turn in:

To receive credit for the project, you need to turn in the completed file "Project1.cpp" and the requested images for each task.

Tasks:

1. (3 points) Implement the function GaussianBlurImage(QImage *image, double sigma) to Gaussian blur an image. "sigma" is the standard deviation of the Gaussian. Use the function MeanBlurImage as a template, and implement the Gaussian blur using a 2D filter. For Gaussian kernel size, use the size = 2 * radius + 1 (similar to the Mean filter) and you can choose the radius as 3 times sigma.

Required: Gaussian blur the image "Seattle.jpg" with a sigma of 4.0, and save as "1.png".

2. (3 points) Implement the function SeparableGaussianBlurImage (QImage *image, double sigma) to Gaussian blur an image using separable filters. "sigma" is the standard deviation of the Gaussian. The separable filter should first Gaussian blur the image horizontally, followed by blurring the image vertically. The final image should look the same as when blurring the image with GaussianBlurImage.

Required: Gaussian blur the image "Seattle.jpg" with a sigma of 4.0, and save as "2.png".

3. (4 points) Implement the functions FirstDerivImage(QImage *image, double sigma) and SecondDerivImage(QImage *image, double sigma) to filter an image with the first and second derivatives of the Gaussian. "sigma" is the standard deviation of the Gaussian. To compute the first derivative, first compute the x-derivative of the image, followed by Gaussian blurring the image. The second derivative should be computed in both directions, i.e. the Laplacian of Gaussian (LoG). For this one, first take first derivatives and then second in both X and Y directions, add them together, and then apply the Gaussian (slide 37 in Filters).

Remember to add 128 to the final pixel values, so you can see the negative values.

Required: Compute the first and second derivatives with a sigma of 1.0 for the image "LadyBug.jpg" and save as "3a.png" and "3b.png".

4. (3 points) Implement the function SharpenImage(QImage *image, double sigma, double alpha) to sharpen an image. "sigma" is the Gaussian standard deviation and alpha is the scale factor (see slide 39 in Filters. ) Hint: Use SecondDerivImage.

Required: Sharpen "Yosemite.png" with a sigma of 1.0 and alpha of 5.0 and save as "4.png".

5. (3 points) Implement SobelImage (QImage *image) to compute edge magnitude and orientation information. SobelImage should display the magnitude and orientation of the edges in an image (see commented code in Project1.cpp for displaying orientations and magnitudes. )

Required: Compute Sobel edge filter on "LadyBug.jpg" and save as "6.png".

6. (3 points) Implement BilinearInterpolation(QImage *image, double x, double y, double rgb[3]) to compute the linearly interpolated pixel value at (x ,y). Both x and y are continuous values (see here. )

Required: The function RotateImage is already implemented and uses BilinearInterpolation to rotate an image. Rotate the image "Yosemite.png" 20 degrees and save as "7.png".

7. (3 points) Implement FindPeaksImage(QImage *image, double thres) to find the peak edge responses perpendicular to the edges. The edge magnitude and orientations can be computed using the Sobel filter you just implemented. A peak response is found by comparing a pixel's edge magnitude to two samples perpendicular to an edge at a distance of one pixel (slide "Non-maximum suppression" in EdgeDetection), call these two samples e0 and e1. Compute e0 and e1 using BilinearInterpolation. A pixel is a peak response if it is larger than the threshold ("thres"), e0, and e1. Assign the peak responses a value of 255 and everything else 0.

Required: Find the peak responses in "Circle.png" with thres = 40.0 and save as "8.png".

8 (a). (5 points) Implement RandomSeedImage(QImage *image, int num_clusters) with randomly selected cluster seeds to perform K-Means Clustering Algorithm using the RGB color space the images come in.

8 (b). (3 points) Next implement PixelSeedImage(QImage *image, int num_clusters) by sampling pixels from the image to find the seeds. Choose a pixel and make its value a seed if it is sufficiently different (dist(L1) = 100) from already-selected seeds. Repeat till you get K different seeds.

In both cases, use use L1 distance between pixels, that is, dist = |Red1 - Red2| + |Green1 - Green2| + |Blue1 - Blue2| and max iteration # = 100.

Required: Perform Random seed K-means clustering on "s06.png" with num_clusters = 4 and save as "9.png" and Pixel seed K-means clustering on "s08.png" with num_clusters = 5 and save as "10.png".

Bell and Whistles (extra credit)

(Whistle = 1 point, Bell = 2 points)

Description: Description: Description: Description: [whistle]

Implement an improved image padded method, i.e. "fixed" or "reflected. "

Description: Description: Description: Description: [whistle]

Histogram K-means implementation - Develop a method for selecting the seeds intelligently from the image using its color histogram (again your code). The seed selection should be automatic, given the histogram and the number of seeds to be selected. One way to go is to find the peaks in the color histogram as candidates for seeds.

Description: Description: Description: Description: [whistle]

Try to filter "Yosemite.png" to resemble an Ansel Adams photograph.

Description: Description: Description: Description: [bell]

  Implement BilateralImage(QImage *image, double sigmaS, double sigmaI) to bilaterally blur an image. "sigmaS" is the spatial standard deviation and "sigmaI" is the standard deviation in intensity. Hint:  The code should be very similar to GaussianBlurImage. Here's the info about bilateral filtering.

Description: Description: Description: Description: [bell]

Implement the Hough transform using the peaks found from FindPeaksImage.

style='mso-spacerun:yes'> You may just output a bunch of images, i.e. , 1.jpg, 2.jpg, 3.jpg, etc. or make a gif animation.

Description: Description: Description: Description: [bell]Description: Description: Description: Description: [bell]

Develop and implement a smarter K-Means variant that determines the best value for K by evaluating statistics of the clusters. Some possible methods to try:

1.Start from the color histogram, as K is closely related to the number of peaks in the histogram. Not all the peaks are necessary as you want only the dominant ones, so you should pick the ones that occupy a certain fraction of the image in terms of pixels.

2.Try clustering using different Ks, and pick the best one. The metric could be related to the distance between clusters and the variance within each cluster.

3. You are free to come up with your own ways.