MATLAB: Image Cdata cannot be complex!!!

image analysismatrix manipulation

hello..i am working on a code which gives me this error Error using ==> image Error using ==> image Image CData can not be complex
Error in ==> imagesc at 19 hh = image(varargin{1},'CDataMapping','scaled');
Error in ==> file1>GABOR_Callback at 794 h = imagesc( gb ); % show the edge image
i dont no how to solve it..help me please..
I = getimage();
I=I(:,:,2);
lambda = 8;
theta = 0;
psi = [0 pi/2];
gamma = 0.5;
bw = 1;
N = 1;
img_in = im2double(I);
%img_in(:,:,2:3) = []; % discard redundant channels, it's gray anyway
img_out = zeros(size(img_in,1), size(img_in,2), N);
for n=1:N
gb = gabor_fn(bw,gamma,psi(1),lambda,theta)...
+ 1i * gabor_fn(bw,gamma,psi(2),lambda,theta);
% gb is the n-th gabor filter
%img_out(:,:,n) = imfilter(img_in, gb, 'symmetric');
% filter output to the n-th channel
figure(1);
imshow(img_in);
title('input image');
figure(2);
imshow(gb);
theta = 15 * n; % next orientation
% Get size of existing image A.
A=img_in;
B=gb;
[rowsA colsA numberOfColorChannelsA] = size(img_in);
% Get size of existing image B.
[rowsB colsB numberOfColorChannelsB] = size(gb);
% See if lateral sizes match.
if rowsB ~= rowsA || colsA ~= colsB
% Size of B does not match A, so resize B to match A's size.
B = imresize(B, [rowsA colsA]);
end
imshow(img_in);
hold on;
h = imagesc( gb ); % show the edge image
set( h, 'AlphaData', .5 ); % .5 transparency
colormap gray ;
end

Best Answer

If you are taking the Gabor transform, you like want to display the magnitude image, change the line
h = imagesc(gb);
to
h = imagesc(abs(gb));