【问题标题】:Colored image by Gabor FiltersGabor 过滤器的彩色图像
【发布时间】:2013-11-22 13:14:53
【问题描述】:

我正在使用 Gabor 过滤器代码,一切似乎都运行良好,但输出图像有问题。 我使用的代码来自这里:Gabor Filters

我创建了 [4x8] 滤光片,它有 8 个方向,每个方向都有不同的波长。


现在我提供了一张图片作为输入:


所以我得到的输出为:


我不应该在黑白中获得一些图像吗?
我的意思是为什么它是彩色的。
当我使用ndims(imgS) 检查尺寸时,它告诉我图像是二维的。


为了清楚起见,这里是 Image 与上述补丁卷积的代码。:

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;

【问题讨论】:

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


    【解决方案1】:

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

    colormap(gray(256));
    

    更多详情请参阅this blog post from The MathWorks

    【讨论】:

    • 如果你是 matlab 用户,你能告诉我如何使用上面获得的图像作为 matlab 中神经网络的特征向量。我想知道究竟应该把什么作为特征。卷积后的单个响应或整个图像
    • @adil:我不是真正的图像处理专家,所以我认为我无法提供帮助,而且这确实是一个与所问问题不同的问题。
    • 好的,谢谢...是的!!!这是属于机器学习的一个单独的,但我问以防万一:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2020-12-19
    相关资源
    最近更新 更多