0
$\begingroup$

According to my question in this link, I applied (with a big help from lennon310) the separability of Gabor filters of any orientation. The only disadvantage of this method is the convolution in the complex domain. So we can treat the Gabor filter G(x,y) as a two dimensional matrix that has a low rank, since the filter is fairly smooth at lower frequencies. Singular value decomposition can then be used in order to decompose the filter into a linear sum of real separable filters.

enter image description here

Here, ui, vi are the columns of the orthogonal matrices U,V. s_i is the singular value. The convolution of the filter G(x, y) with the image I(x, y) can now be approximated using: enter image description here

Please I need a help about how can I edit my code in this link in order to apply that in MATLAB. Any help will be very appreciated.

$\endgroup$
1
$\begingroup$

I won't recommend you apply SVD in your Gabor filter, since it does not bring much benefit but increase the computing load. If you implement SVD, you may not separate the filter at first, instead the SVD is performed on the 2D Gabor filter:

                for i = -filtSizeL:filtSizeR
                    for j = -filtSizeL:filtSizeR

                        if ( sqrt(i^2+j^2)>filtSize/2 )
                            E = 0;
                        else
                            x = i*cos(theta) - j*sin(theta);
                            y = i*sin(theta) + j*cos(theta);
                            E = exp(-(x^2+G^2*y^2)/(2*sigmaq))*cos(2*pi*x/lambda(k));
                        end
                        f(j+center,i+center) = E;
                    end
                end

               %% SVD %%%%
               [u,s,v]=SVD(f);

With u, s, and v, you implement the convolution with your image:

    convv = zeros(size(image_double));
    for i = 1:filtSizeR+filtSizeL+1
        convv1=imfilter(image_double*s(i,i),  u(i,:),'conv');
        convv2=imfilter(double(convv1),v(:,i)','conv');
        convv = convv + convv2;
    end

    figure
    imagesc(imag(convv));

Yet I don't think this method is as good as your separable f and g method.

$\endgroup$
  • $\begingroup$ I would like to thank you so much for your response! Ok so you applied firstly the SVD, but what is the T in USV (shown in the formula of my question) ?.advance! $\endgroup$ – Christina Jan 21 '14 at 21:13
  • 1
    $\begingroup$ T is the transpose symbol, I used v(:,i)' in the code $\endgroup$ – lennon310 Jan 21 '14 at 21:14
  • $\begingroup$ And please can you tell me why you took K as i=1:filtSizeR+filtsizeL+1 ? ah what is the difference between v(i,:) and v(:.i) ? finally, in the paper, they demonstrated that this method is more optimal than separable Gabor in terms of time complexity, so what is your opinion :) $\endgroup$ – Christina Jan 21 '14 at 21:17
  • 1
    $\begingroup$ for i = -filtSizeL:filtSizeR means the size of f is filtSizeR+filtsizeL+1. v(i,:) is the ith row of v, and v(:,i)' is the ith row of v'. I don't think svd is better in time complexity, even if it is, the space complexity is very high: if size(f) is large, svd will be very slow, or even cannot finish due to OUT OF MEMORY error $\endgroup$ – lennon310 Jan 21 '14 at 21:23
  • $\begingroup$ But in the paper, they told that K is <4, so in your code, firstly K is equal to 7, secondly to 9 etc. ? $\endgroup$ – Christina Jan 21 '14 at 21:38
1
$\begingroup$

The final code will be:

for i = -filtSizeL:filtSizeR
            for j = -filtSizeL:filtSizeR

                if ( sqrt(i^2+j^2)>filtSize/2 )
                    E = 0;
                else
                    x = i*cos(theta) - j*sin(theta);
                    y = i*sin(theta) + j*cos(theta);

                     %fx = exp(-(i^2)/(2*sigmaq))*exp(sqrt(-1)*i*cos(theta));
                     %gy = exp(-(j^2)/(2*sigmaq))*exp(sqrt(-1)*j*sin(theta));
                     %E=real(fx*gy);

                   E = exp(-(x^2+G^2*y^2)/(2*sigmaq))*cos(2*pi*x/lambda(k));
                end
                f(j+center,i+center) = E;
            end
        end

        f = f - mean(mean(f));
        f = f ./ sqrt(sum(sum(f.^2)));

%%%% SVD %%%%
        [u,s,v]=svd(f);

 convv = zeros(size(image_double));
   for i = 1:filtSizeR+filtSizeL+1
       convv1=imfilter(image_double*s(i,i),  u(i,:),'conv');
        convv2=imfilter(double(convv1),v(:,i)','conv');
        convv = convv + convv2;
    end

    figure
    imagesc(convv);
    colormap(gray);
$\endgroup$
  • 1
    $\begingroup$ looks good to me :) $\endgroup$ – lennon310 Jan 21 '14 at 22:33

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.