简体   繁体   中英

Gabor based Texture Segmentation

I am trying to implement a gabor filter for use in textured image segmentation. I am doing this in MATLAB and consulting the concepts from paper - A level set and Gabor-based Active Contour Algorithm for Segmenting Textured Images

I am highlighing the relevant parts below: The 2D gabor function is given as

在此输入图像描述

where

在此输入图像描述

The frequency of the span-limited sinusoidal grating is given by F and its orientation is specified by Theta . Sigma is the scale parameter. This filter is to be used on an image and as the gabor filter consists of an imaginary component, the Gabor transform is obtained as shown below.

在此输入图像描述

where, GR and GI are the real and imaginary parts obtained by convoluting it with an image u0. I need to code this part in MATLAB and generate the Gabor transformed image for the different values of theta, F and sigma

My code

clc;clear all;close all;
sigma=.0075;
m_size=7;
theta=pi/4;
F=60;
[real_g,im_g]=gabor(m_size,sigma,F,theta);

//My Gabor function
function [real_g,im_g] = gabor(m_size,sigma,F,theta)
[x,y]=meshgrid(1:m_size,1:m_size);
real_g = zeros(m_size);
im_g = zeros(m_size);
g_sigma = zeros(m_size);
for i=1:size(x,1)
    for j=1:size(y,1)
        g_sigma(i,j) = (1./(2*pi*sigma^2)).*exp(((-1).*(i^2+j^2))./(2*sigma^2));
        real_g(i,j) = g_sigma(i,j).*cos((2*pi*F).*(i.*cos(theta)+j.*sin(theta)));
        im_g(i,j) = g_sigma(i,j).*sin((2*pi*F).*(i.*cos(theta)+j.*sin(theta)));
    end
end

My output

>> real_g

real_g =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0

>> im_g

im_g =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0

My gabor filter is completely wrong . Please could you guys help me to construct the correct gabor filter ? Please note that the data for the parameters and the formula is taken from the paper I already referred.

Any help will be greatly appreciated. PS If anybody needs the paper I can mail it too. Thanks.

Hopefully the below codes would be of some use to what you are working on. It demonstrate how to transform an image using your Gabor filter with varying thetas (as shown in the images). Cheers.

具有不同θ的图像

% get image
u0=double(imread('cameraman.tif'));

% initialize parameters
sigma = 3;
m_size = 7;
F = 1;
m_size_halfed = round((m_size-1)/2);

% make up some thetas
thetas=0:pi/5:pi;

% loop through all thetas
for i = 1:numel(thetas)    
theta = thetas(i);

% setup the "gabor transform"
[x,y]=meshgrid(-m_size_halfed:m_size_halfed,-m_size_halfed:m_size_halfed);
g_sigma = (1./(2*pi*sigma^2)).*exp(((-1).*(x.^2+y.^2))./(2*sigma.^2));
real_g = g_sigma.*cos((2*pi*F).*(x.*cos(theta)+y.*sin(theta)));
im_g = g_sigma.*sin((2*pi*F).*(x.*cos(theta)+y.*sin(theta)));

% perform Gabor transform
u_0sft=sqrt(conv2(u0,real_g,'same').^2+conv2(u0,im_g,'same').^2);

subplot(1,numel(thetas)+1,i+1)
imagesc(u_0sft);
colormap('gray'); axis image; axis off;
title(sprintf('theta:%1.1f',theta));

end

% visualize image
subplot(1,numel(thetas)+1,1)
imagesc(u0);
colormap('gray'); axis image; axis off;
title('original');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM