将Gabor滤波器应用于图像

3

我是一个对图像处理完全陌生的人。我想知道如何在一张视网膜图像上应用12个不同方向(例如0、15、30、45至165度)的gabor滤波器。我希望能够将这12个方向的gabor滤波器应用到图像上,并显示每个方向的输出结果。我的输入是一张视网膜图像,每个方向的输出应该是经过gabor滤波器处理后的精细调整的视网膜图像。请问如何实现?

 %code for gabor filter                
 I = getimage();         
 I=I(:,:,2);    
 lambda  = 8;    
theta   = 0;    
psi     = [0 pi/2];    
gamma   = 0.5;    
 bw      = 1;    
 N       = 12;    
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       
        %theta = theta + 2*pi/N;          
        theta = 15 * n;   % i wrote this because my angles are multiples of 15       
        % next orientation           
 end 

 figure(1);           
 imshow(img_in);                  
 title('input image');                    
 figure(2);            
 img_out_disp = sum(abs(img_out).^2, 3).^0.5;        
 %default superposition method, L2-norm        
 img_out_disp = img_out_disp./max(img_out_disp(:));           
 % normalize        
 imshow(img_out_disp);         
 title('gabor output, L-2 super-imposed, normalized');        

我的输入图像是 enter image description here
而我的输出图像是 enter image description here
如何通过应用Gabor滤波器将我的图像定向为12个不同的方向?
我本来应该得到一个视网膜图像的输出,但是我得到的输出图像是 enter image description here

你所看到的是你正在使用的 Gabor 滤波器的可视化。你需要将这个滤波器应用到视网膜图像上,才能得到想要的图像。 - skytreader
哦哦,好的先生...我会尝试做到的...非常感谢您先生。 - vidya
先生,我该如何将这个滤波器应用于视网膜图像。我尝试使用conv2函数但没有成功,还有其他方法吗? - vidya
最后的图像是滤波器的图像,对吗? - zenpoy
是的先生,它是过滤器图像,现在我想将此图像施加到我的原始图像上。 - vidya
2个回答

2
你应该添加这两行代码:
...
% gb is the n-th gabor filter 
img_out(:,:,n) = imfilter(img_in, gb, 'symmetric');   
figure;
imshow(img_out(:,:,n));
...  

先生,我已经尝试过相同的方法,但没有得到正确的输出。我想要我的上传的输出图像有两个不同的方向。而且我认为可以通过两个图像的叠加来获得输出,即通过我的原始图像和for循环中的img_out...我不知道我是否正确,只是猜测。 - vidya
你在问题中写了12种不同的方向。能否在问题中具体说明您已经尝试了什么以及哪些无法正常工作?附上的代码是您自己编写的吗?因为您实际上正在创建所需的所有图像,您只需将它们分别显示即可。 - zenpoy
好的先生,我会编辑我的问题。我已经尝试了这个程序,但是我的输出图像不正确。 - vidya
Siri,我得到了可视化的输出结果。我想将这12个不同的输出结果叠加到我的原始图像上,我该怎么做? - vidya

0

我从你的问题中理解到,你想要应用12次Gabor滤波器,并且每次都有指定的方向(theta),对吗?

要做到这一点——>在for循环之前写入以下内容——>

responses = {}; % to save each response from filter.

在过滤图像之后,像这样卷积它 ---->
...

response =  conv2(img_in,gb,'same'); 

...

然后可以通过以下方式获取振幅 --->...

realpart = real(response);
imagpart = imag(response);
response = sqrt(realpart.^2 + imagpart.^2);

...

将 ---> img_out(:,:,n) 替换为 ---->
...

responses = cat(1,responses,response);

这段代码将会把每个筛选器的响应保存到一个单元格中,如果你想查看响应,只需要执行以下操作...

X = responses{1}; % or 2 or 3...

这个链接将提供更好的关于Gabor滤波器的信息 http://matlabserver.cs.rug.nl/edgedetectionweb/web/edgedetection_params.html

希望这能帮到你。 最好的问候。


2
请您正确编辑您的帖子,现在它几乎无法阅读。 - Ander Biguri
Ander Biguri,我编辑了我的帖子并使其可读,谢谢。 - saif

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接