使用Gabor滤镜的图像处理

使用Gabor滤镜的图像处理

本文介绍了使用Gabor滤镜的图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对图像执行gabor过滤器.

I am trying to execute gabor filter on images.

%% Read

clear all;
close all;
clc;
I=imread('test.png');
imshow(I);

%% Crop
I2 = imcrop(I);
figure, imshow(I2)
m=size(I2,1);
n=size(I2,2);
%% Gabor
phi = 7*pi/8;
theta = 2;
sigma = 0.65*theta;
for i=1:3
    for j=1:3
        xprime= j*cos(phi);
        yprime= i*sin(phi);
        K = exp(2*pi*theta*i(xprime+ yprime));
        G= exp(-(i.^2+j.^2)/(sigma^2)).*abs(K);
    end
end

%% Convolve

for i=1:m
    for j=1:n
       J(i,j)=conv2(I2,G);
    end
end
imshow(uint8(J))

我总是收到此错误.

??? Subscript indices must either be real positive integers or logicals.

不确定如何解决此问题...

Not sure how to solve this...

推荐答案

i和括号之间的K = exp(2*pi*theta*i(xprime+ yprime));中缺少*.您喜欢的应该是K = exp(2*pi*theta*i*(xprime+ yprime));.由于这种情况,Mathworks建议使用sqrt(-1)作为虚数.

You are missing a * in K = exp(2*pi*theta*i(xprime+ yprime)); between i and the parentheses. You like should be K = exp(2*pi*theta*i*(xprime+ yprime));. It is because of such cases Mathworks recommends using sqrt(-1) for the imaginary number.

更新:您无需循环即可在Matlab中进行卷积.您只需说J=conv2(I2,G);

Update:You don't need a loop to do convolution in Matlab. You simply say J=conv2(I2,G);

更新2:

这是工作代码

%% Gabor
phi = 7*pi/8;
theta = 2;
sigma = 0.65*theta;
filterSize = 6;

G = zeros(filterSize);


for i=(0:filterSize-1)/filterSize
    for j=(0:filterSize-/filterSize
        xprime= j*cos(phi);
        yprime= i*sin(phi);
        K = exp(2*pi*theta*sqrt(-1)*(xprime+ yprime));
        G(round((i+1)*filterSize),round((j+1)*filterSize)) = exp(-(i^2+j^2)/(sigma^2))*K;
    end
end

%% Convolve

J = conv2(I2,G);
imshow(imag(J));

这篇关于使用Gabor滤镜的图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:13