Analysis of the texture image by using Gabor transform matlab code implemented

Gabor change is a windowed Fourier transform, Gabor function can extract relevant features at different scales, in different directions in the frequency domain. Gabor and biological function similar to the role of the human eye, so often used on texture recognition, and achieved good results.

Gobor two-dimensional filtering function:

among them:

xp = x * cos (theta) + y * sin (theta)

yp = y * cos (theta) -x * sin (theta)

function [ G,gabout ] = gaborfilter(I,Sx,Sy,f,theta)
% gaborfilter定义,I为输入图像,Sx、Sy是变量在x,y轴变化的范围,即选定的gabor小波窗口的大小
% f为正弦函数的频率,theta为gabor滤波器的方向。G为gabor滤波函数g(x,y),gabout为gabor滤波后的图像
if isa(I,'double')~=1
    I = double(I);
end
for x = -fix(Sx):fix(Sx)
    for y=-fix(Sy):fix(Sy)
        xp = x * cos(theta) + y * sin(theta);
        yp = y * cos(theta) - x*sin(theta);
        G(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*((xp/Sx)^2+(yp/Sy)^2))*cos(2*pi*f*xp);
    end
end
Imgabout = conv2(I,double(imag(G)),'same');
Regabout = conv2(I,double(real(G)),'same');
gabout = sqrt(Imgabout.*Imgabout+Regabout.*Regabout);  %gabor小波变换后的图像gabout
end
close all;clear all;clc;
I = imread('wenli.jpg');
I=rgb2gray(I);
[G,gabout]=gaborfilter(I,2,4,16,pi/10);  %调用garborfilter()函数对图像做小波变换
J = fft2(gabout);  %对滤波后的图像做fft变换(快速傅里叶),变换到频域
A = double(J);
[m,n] = size(A);
B = A;
C = zeros(m,n);
for i=1:m-1
    for j=1:n-1
        B(i,j) = A(i+1,j+1);
        C(i,j) = abs(round(A(i,j)-B(i,j)));
    end
end
h = imhist(mat2gray(C))/(m*n);
mean = 0;con=0;ent=0;
for i=1:256   %图像的均值,对比度和熵
    mean = mean+(i*h(i))/256;
    con = con+i*i*h(i);
    if(h(i)>0)
        ent = ent-h(i)*log2(h(i));
    end
end
figure;
subplot(121);imshow(I);
subplot(122);imshow(uint8(gabout));
mean,con,ent
To original left, right is the texture image process gabor pi / 10 direction

 

To original left, right is the texture image process gabor pi / 4 direction

 

  mean (average) CON (contrast) Ent (entropy)
theta=pi/10 0.0043 1.6111 0.4046
theta=pi/4 0.0042 1.5869 0.3623

Entropy energy reflected image, when the image direction and the grain direction anastomosis filter, the greater the energy output image. This demonstrates the Gabor function can capture a considerable amount of texture information, with excellent spatial characteristics.

Guess you like

Origin www.cnblogs.com/wojianxin/p/11432280.html