Gabor Filters的彩色图像

时间:2013-11-10 20:01:31

标签: image matlab image-processing grayscale feature-extraction

我正在使用Gabor过滤器代码,一切似乎运行正常,但我遇到输出图像问题。 我使用的代码来自此处:Gabor Filters

我创建了[4x8]个过滤器,每个过滤器有8个不同波长的方向。

Gabor Filters


现在我给了一个图像作为输入:

Car

所以输出为:

enter image description here


我不是想要获得一些黑白图像 我的意思是为什么它是有色的。
当我使用ndims(imgS)检查尺寸时,它会告诉图像是2-D。


为了清楚起见,下面是使用上述补丁对图像进行卷积的代码:

function [img]=Convolve_Gabor(R,C,GW,img)
%if not grayscaled then grayscale it
if ndims(img)>2
    img=rgb2gray(img);
end

%Convert to Double so that its accepteble everywhere
img=im2double(img);

% Store the original size.
[m,n] = size(img);

%{
 The minimum amount of padding is just "one side" of the filter.
 We add 1 if the image size is odd.
 assuming the filter size is odd.
%}

pR = (R-1)/2; % make pR half of R
pC = (C-1)/2; % make pC half of C

if rem(m,2) ~= 0; pR = pR + 1; end; % if image height is odd make pR even
if rem(n,2) ~= 0; pC = pC + 1; end; % if image width is odd make pC even
img = padarray(img,[pR pC],'pre'); % Pad image to handle circular convolution.

% Pad all the filters to size of padded image.
% We made sure padsize will only be even, so we can divide by 2.
padsize = size(img) - [R C];
GW = cellfun( @(x) padarray(x,padsize/2),GW,'UniformOutput',false);

imgFFT = fft2(img); % Pre-calculate image FFT.
imgfilt={};
for i=1:length(GW)
    filter = fft2( ifftshift( GW{i} ) ); % See Numerical Recipes.
    imgfilt{i} = ifft2( imgFFT .* filter ); % Apply Convolution Theorem.
end

%# Sum the responses to each filter. Do it in the above loop to save some space.
imgS = zeros(m,n);

for i=1:length(imgfilt)
    imgS = imgS + imgfilt{i}(pR+1:end,pC+1:end); % Just use the valid part.
end
disp(ndims(imgS));
figure,imagesc(abs(imgS)),hold on;

1 个答案:

答案 0 :(得分:3)

仅仅因为图像只有一个通道,即数据是二维矩阵,并不意味着它不能转换为三维RGB空间。此技术称为indexed color(与truecolor相对)。看起来Matlab正在使用默认的jet色彩图将数据转换为颜色。如果您希望图像显示为灰度,请在绘图后使用colormap功能:

colormap(gray(256));

有关详细信息,请参阅this blog post from The MathWorks