1

This is code for serial Gabor filters. The problem I am getting is the statement J = J + abc should return a final filtered image as a superposition of all filters but only the result of the last iteration is displayed:

function [J] = gabor(I)

J = zeros(size(I));

for phi = 5*pi/8:pi/8:pi;
    for theta = 1:0.5:2;
        for filterSize = 4:6;
            sigma = 0.65*theta;
            G = zeros(filterSize);

            for i=(0:filterSize-1)/filterSize
                for j=(0:filterSize-1)/filterSize
                    xprime= j*cos(phi);
                    yprime= i*sin(phi);
                    K = exp(2*pi*theta*sqrt(-1)*(xprime+ yprime));
                    G(round((i+1)*filterSize),round((j+1)*filterSize)) = exp(-(i^2+j^2)/(sigma^2))*K;
                end
            end

        abc = conv2(double(I),double(G),'same');
        J = J + abc;
        end
    end
end
figure; imshow(J);
end

Here is what the output image looks like:

blah

rayryeng
  • 102,964
  • 22
  • 184
  • 193
akshay
  • 13
  • 3

1 Answers1

1

My gut feeling (or it rather looks like...) is that your image output type is double, and imshow only displays intensities between [0,1] for class double. Any values that are below 0 or above 1 get saturated to black or white respectively, which is why your image output only appears to be black or white. This is also apparent as J is defaulted to a double type. Try doing this for your imshow command so that it stretches the intensities to fit within the [0,1] range:

imshow(J, []);  

Take note that this does not modify the image. It only changes how the image is visualized. This imshow command appears at the end of your code, and so change that command here.

By the way, sqrt(-1) is considered bad form. Use 1j or 1i instead, and change your for loop indices so that you're not using i and j as these should be used to represent the complex number. It has been shown by Shai that using i and j as loop indices can lead to poor performance. You should reserve these for the complex number instead. Check this post out for more details: Using i and j as variables in Matlab

Also, you probably want to contrast stretch the image so that it does fit between 0 and 1. As such, do this before you exit your function:

J = im2double(J);
Community
  • 1
  • 1
rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • sorry for the late reply but THANKS A TON it worked like the way i wanted to its just that sometimes the error is staring at you and you cant figure it out....thanks again – akshay Aug 18 '14 at 20:46
  • @akshay - You're welcome. If my post helped you, please consider accepting it. Click on the checkmark icon at the top of my post, to the left below the up and down vote buttons. Thanks! – rayryeng Aug 18 '14 at 20:51