am getting error in result(r,:​)=ifft2(im​agefft.*fi​lter); please help me ...

1 view (last 30 days)
this is my code
function [gaborFeature] = gaborConvolve(im)
% im - the image to convolve
%
% Output:
% gaborFeature - a 1D cell array of complex valued comvolution results
% minWaveLength - wavelength of the basis filter
sigmaOnf = 0.5;
% sigmaOnf - Ratio of the standard deviation of the Gaussian describing
% the log Gabor filter's transfer function in the frequency
% domain to the filter center frequency.
minWaveLength = 18;
I=imread('C:\Users\Bhagya Vinod\Documents\MATLAB\Dataset\images\01\very.jpg');
grayImage = rgb2gray(I);
histEql = adapthisteq(grayImage,'clipLimit',0.02,'Distribution','rayleigh');
BW = wiener2(histEql,[5 5]);
% object in the image is represented by white colour
% background is represented by black colour
I1 = 255 - BW;
% Invert the image
SE = strel('square',3); % generate the structuring element
D = imdilate(I1,SE); % Perform Dilation Operation
[rows cols] = size(D);
ndata = cols;
radius = [0:fix(ndata/2)]/fix(ndata/2)/2; % Frequency values 0 - 0.5
% Construct the filter - first calculate the radial filter component.
fo = 1.0/minWaveLength; % Centre frequency of filter.
% corresponding to fo.
logGabor(1:ndata/2+1) = exp((-(log(radius/fo)).^2) / (2 * log(sigmaOnf).^2));
filter = logGabor;
% for each row of the input image, do the convolution, back transform
for r = 1:rows % For each row
signal = D(r,1:ndata);
imagefft = fft2( signal );
result(r,:) = ifft2(imagefft .* filter);
end
gaborFeature.gabMag = real(result);
gaborFeature.gabPhs = imag(result);
the error is "Error using .* Matrix dimensions must agree.
Error in gaborConvolve (line 50) result(r,:) = ifft2(imagefft .* filter);"
  2 Comments
KSSV
KSSV on 19 Apr 2018
Please specify what error you get? Or copy the error message here.
Bhagya Vinod
Bhagya Vinod on 19 Apr 2018
Error using .* Matrix dimensions must agree.
Error in gaborConvolve (line 50) result(r,:) = ifft2(imagefft .* filter);

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 19 Apr 2018
ndata = cols;
logGabor(1:ndata/2+1) = exp((-(log(radius/fo)).^2) / (2 * log(sigmaOnf).^2));

so we know that logGabor is one longer than half of the number of columns. For example 480 columns would give logGabor of length 241.

filter = logGabor;

... and that's what the filter is.

for r = 1:rows	% For each row
    signal = D(r,1:ndata);
    imagefft = fft2( signal );
    result(r,:) = ifft2(imagefft .* filter)

Based on the for we can see that r is a scalar, so D(r,1:ndata) is one complete row out of D, a row vector.

fft2() of a row vector is an unusual thing to do, but it works out the same as fft() of the row vector. The result is a row vector of the same length, which in this case is the full number of columns of the image.

Now imagefft .* filter is a row vector the same width as the image, .* a row vector that is 1 more than half the number of columns. In the 480 example I gave above that would be (1 x 480) .* (1 x 241). That is an error.

It is possible that you want to use

filter = [logGabor, conj(fliplr(logGabor))]

or possibly

filter = [logGabor, fliplr(logGabor)]

if the idea is to filter the left and right halves of the fft result the same way. But if so then you need to be careful about what you do with the DC component in imagefft(1) which does not share in the symmetry of the fft. You would also need to pay close attention to whether the image was an odd number of columns or an even number of columns.

  2 Comments
Walter Roberson
Walter Roberson on 19 Apr 2018
You have a filter that is just over half of the length of the data to be filtered. What is your intended result from the filtering?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!