0
$\begingroup$

I have an image of size 160x160 of pixels. I am trying to convolve this image with two Gabor filters of different scales (7 and 9 respectively) but with the same orientation. I red in an article the following phrase :

The maps (the results of the two convolution operations) have the same dimensionality but they are the outputs of different filters.

After convolving my image (conv2) with these two gabor filters (scales 7 and 9), i got the following results :

The 2 maps (one image after convolving with gabor of scale 7 and the other after convolving with gabor of scale 9) have different dimensionality!

So according to the phrase 1) , why my maps have different sizes ? it is normal ? or false ? i need your opinions.

In other words, i filtered my image with a gabor filter of scale 7, then i filtered my image with another gabor with scale 9 . So i got two maps. Is these maps must have the same size or not ?

$\endgroup$
  • $\begingroup$ @lennon310 sure my email was christina_rodriguez@hotmail.com, but it is blocked now:( , So I create another one : Liszt_2014@hotmail.com ,, jaja my real name is christina but my email is liszt because my favorite pianist is Lisztttt :) $\endgroup$ – Christina Jan 5 '14 at 11:35
0
$\begingroup$

If you're using just straight 2D convolution, you will get the full output. What I think you want is conv2(A, B, 'same').

To better understand this, 1D convolution between two sequences with length N & M results in a final sequence of length = N + M - 1. So without any truncation your conv2 result will no longer be of size 160x160, but (160+M-1)x(160+M-1).

If you're using Matlab, see 'help conv2', 'help filter2', 'help imfilter' (if you have the image processing toolbox installed). imfilter defaults to 'same'.

I'll add a little more discussion regarding filter sizes when they contain exponential functions.

Given in reality were sampling a function that extends to infinity in all directions, albeit the values become insignificant at some point, the function does extend that far. The implementation you're referencing fixes the limits to 3 standard deviations, because that's good enough for them. I saw another implementation that used 8. If you're scale, or sigma, is very large, you run the possibility of the filter turning out to be larger than the image you'll be filtering against. What do you do then? Because like I stated earlier, straight convolution produces a sequence that is N + M - 1.

You need to grab only the central part of that result. The central part would also be of the same size as the image your filtering. That's what the 'same' flag does.

One other point I'd like to make is that there's nothing stopping you from just creating a filter that is the same size as your image. Instead of using sigma as the size controller, just specify the dimension of the filter. Given convolution is often times done in the frequency domain, you're going to be zero padding and taking a larger FFT anyway. Look for references on fast convolution using the FFT.

Let's say you're image size is 256x256 and you're filter is 32x32. Here's a simple example without using power of 2 FFT's.

N = 256;
M = 32;
K = N + M - 1; % Length of full convolution

x = randn(N, N);
y = ones(M, M);

% Spatial domain convolution (slow)
r = conv2(x, y, 'same');

% Spatial frequency domain convolution (fast)
z = ifft2(fft2(x, K, K).*fft2(y, K, K));
idx = round((K-N)/2+1):round((K+N)/2); % Indices of the central portion
z = z(idx, idx); % Obtaining the central part of the result

subplot(311), imagesc(r), axis('square'), colorbar
subplot(312), imagesc(z), axis('square'), colorbar
subplot(313), imagesc(abs(r-z)), axis('square'), colorbar

enter image description here

$\endgroup$
  • $\begingroup$ No what i am trying to explain in my question is that, i filtered my image with a gabor filter of scale 7, then i filtered my image with another gabor with scale 9 . So i got two maps. Is these maps must have the same size or not ? $\endgroup$ – Christina Dec 10 '13 at 19:37
  • $\begingroup$ It depends. How did you define or implement your Gabor filter? If you used the first hit on the Matlab File Exchange for Gabor Filter you'll find that he (somewhat arbitrarily) fixes the size of the filter like this sz=fix(8*max(sigma_y,sigma_x)); $\endgroup$ – porten Dec 10 '13 at 19:57
  • $\begingroup$ To create my gabor, i used the code written in wiki link en.wikipedia.org/wiki/Gabor_filter. ,,, but when we filter firstly our image with a gabor of scale 7 and then with gabor of scale 9 ,, the two result images must take different sizes ? or can take the same dimension ? $\endgroup$ – Christina Dec 10 '13 at 20:08
  • $\begingroup$ Regardless of the size of the filter, you need to ensure that the resulting convolution or filtering process produces the same size as the original image, unless you desire the full result. There's nothing wrong with having different size filters. You're implementation will actually produce different size filters depending on the parameters. $\endgroup$ – porten Dec 10 '13 at 20:19
  • $\begingroup$ sure i need to use different scales of filters. So when we convolve an image with a Gabor of scale 7 , the result of this convolution take the size NxM ,, and when we convolve the image with gabor of scale 9 , the result take the size N'xM' ,, so NxM must be different than N'xM' ? because we filtering the image with two different scales of filters, is it true ? $\endgroup$ – Christina Dec 10 '13 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.