CSC 370

CSC 370 Assignment: Texture

 

For this assignment, you will explore how texture filters work with images. We will be using a particular type of texture filter called the Gabor filter. A Gabor filter is created by combining an oriented sinusoid function with a Gaussian envelope. It therefore responds to a particular orientation of texture at a particular scale. Although a typical application would use many such filters, we will use only six, corresponding to a particular scale of texture

The Filters

The filters we will be using are stored as a cell array in the file GaborFilters.mat. (If you are working in the labs, you shouldn't need to download this file: it is already on the servers.) The following code will display surface plots of the six filters:

>> load GaborFilters
>> for i = 1:6
  subplot(2,3,i);
  surf(gabor{i});
end;

Note that the six filters are stored in a data type we haven't seen before, called a cell array. Cell arrays are a very flexible data type in Matlab. They behave like ordinary matrices in many respects, with two key differences: the elements of a cell array are referenced using curly braces instead of parentheses, and each element of a cell array can hold any Matlab variable value -- matrix, string, struct, or even another cell array. The types don't even have to match, as shown in this example:

>> a = cell(2,3);
>> a{1,1} = 'Hello world.';
>> a{2,1} = rand(2);
>> a{2,2} = 7;
>> a{2,3} = cell(1,2);
>> a
a = 
    'Hello world.'     []            []
      [2x2 double]    [7]    {1x2 cell}
>> 

Note also the use of the function cell here, which creates an empty cell array.

In any case, the way we are using cell arrays here, you may refer to the six filters we'll use as gabor{1} through gabor{6}.

Exercise

Consider the image below, which contains lots of different textures. Before doing anything else, look at the filters shown in the previous section and try to predict where in this image each filter will respond most strongly. Record this information.

Now filter the image using each of the six filters. (Note that you will first have to make sure the pixel values have type double, not uint8.) Since the filter response may be either positive or negative to a particular texture, you will need to take the absolute value. Now display the result for each of the six filter types. Can you explain the results? Do they look as you had expected?

Now subsample the image twice, and apply the six filters again. Do the results look different at this scale?

A note on subsampling: It is customary to smooth slightly before the subsampling operation. You can either use a 2D filter or a combination of two 1D filters, one oriented in each direction. Then extract every other pixel.

img = conv2(img,[1 2 1; 2 4 2; 1 2 1]/16);
img = img(2:2:end,2:2:end);
% or, slightly faster:
img = conv2(img,[1 2 1]/4);
img = conv2(img,[1 2 1]'/4);
img = img(2:2:end,2:2:end);

Finally: see if you can find the scale and orientation that responds most strongly to the zebras in the center of the image. You can use imresize to rescale the image to a variety of fractional scales. Make a loop to try them out, and plot the strength of the mean response with respect to scale factor. (Take the root-mean-square values of the filter response across the whole image patch, and plot this number with respect to scale and orientation.)

zebra stripes