In the final part of the assignment you will explore how to represent the texture of an image, and then use this representation in the clustering algorithm you developed in the previous section.
As we saw in class, linear filters allow you to modify an image in some way. To get you warmed up, write a function that creates a Gaussian filter and then applies it to an image. Your function should have the following signature:
function filter = gaussFilter( sigma );where sigma is the standard deviation of the Gaussian. Use the equation at the bottom of page 137 for guidance on how to construct the kernel. Choose a reasonable number for the size of your filter matrix. (Think about what happens to the value Gaussian as it gets further from the center of the filter matrix).
Apply filters with a few different values of sigma to a grayscale image of your choice using the matlab function imfilter. Show your results below. No need to include the link to your code.
In this part you will implement the difference-of-gaussians filter-based texture representation described in section 9.1 of Forsyth & Ponce. First, write a function that creates a difference of gaussians filter. This function should have the following signature:
function filter = DOGFilter(sx, sy, theta, w);sx and sy are vectors standard deviations in the x and y directions, respectively, where sx(g) and sy(g) give the standard deviation in the x and y direction, respectively, for the gth Gaussian. theta is the angle of rotation for the "bars", and w is a weight vector used when taking the weighted sum of the Gaussians.
There are a couple of ways you can produce a matrix of output from a rotated Gaussian. One way you can do this is to first produce the matrix from the unrotated Gaussian function, and then rotate that matrix using the imrotate function (because afterall, what you are dealing with here is rather like an image). This was the way that I had originally suggested you
A second, and arguably more correct, way of doing this is simply to express a given input (i,j) in a coordinate system that has been rotated by &theta, producing (i',j') as the coordinates of the same point in the new coordinate system. Then use (i',j') as the input into the Gaussian function, which is not rotated relative to this new coordinate system. This web site gives a simple, clear picture of how to express a point (x,y) in a rotated coordinate system, and should help you understand what you need to do if it's not clear.
Using your function, create each of the 8 filters described on page 191 (and shown on page 192) of F&P. Visualize your filters as images (as is done in F&P) and show the results below. Also include a link to your code:
Finally, we want to use texture in segmentation. To do this, we first need to compute a texture statistic from the output of applying the filters in the previous step to an image. Write a function that applies a filter to an image and then uses the output to compute a texture statistic for each pixel in the image. The texture statistic we will compute is the mean squared response over a fixed-sized window in the filtered image, as described on page 194 in F&P. Make the size of the window an input to your function, so you can vary it depending on the image you are trying to segment.
Finally, use the output of your texture analysis as features in your segmentation algorithm to segment an image by texture. Try segmenting a number of images on texture alone.
Include below a link (or links) to the code you wrote to compute the texture statistic, some successful and not-so-successful results below along with a short discussion of when texture segmentation worked well and when it didn't. For fun, I will put some texture images into the image repository soon (just as soon as I can write to it...).
Remember that you need to pursue only one extension in one part of the assignment, and it can be anything you'd like to investigate. These are only suggestions.