Hello, I'm trying to write the Gabor ternary pattern, Please help me with this!

Hello, I'm trying to write the GAbor ternary pattern:
The answer should be like below:
Please tell me where did I wrong in code!
MATLAB Code:
clc
close all
clear all
[fn fp]=uigetfile('*.*');
I=(rgb2gray(imread([fp,fn])));
[m n]=size(I);
kv=pi/2;
GTP=zeros(m,n);
for x=1:m
for y=1:n
for ii=0:3
phi=ii*pi/4;
z=[x y]';
k=kv*[cos(phi) sin(phi)]';
psi(x,y)=((norm(k))^2)*exp(-(((norm(k))^2)*((norm(z))^2))/2)*...
(exp(sqrt(-1)*k'*z)-exp(-1/2));
G(x,y)=imag(psi(x,y));
f(x,y)=conv(G(x,y),I(x,y));
if f(x,y)<-.03
pp=-1;
else pp=0;
end
GTP(x,y)=3^ii*(pp+2*(f(x,y)>.03))+GTP(x,y);
end
end
end
figure,imshow(GTP)
Thanks for your considration

2 comentarios

Mehran - perhaps describe what problems you are having with your code. Is the problem that the output image is all zeros, or something else?
Yes the output image is zeros but it should be like the Posted Image! Don't know what is wrong with my code!

Iniciar sesión para comentar.

 Respuesta aceptada

Mehran Kh
Mehran Kh el 25 de Oct. de 2014
Editada: Mehran Kh el 25 de Oct. de 2014
I found why I get Zeros in output image!Convolution (f and GTP) should be out of loop!
clc
close all
clear all
[fn fp]=uigetfile('*.*');
I=im2double(rgb2gray(imread([fp,fn])));
I=zscore(I);
[m n]=size(I);
kv=pi/2;
t=0.03;
GTP=zeros(m,n);
for x=1:m
for y=1:n
z=[x y]';
k0=kv*[cos(0) sin(0)]';
psi0(x,y)=norm(k0)^2*exp(-norm(k0)^2*norm(z)^2/2)*...
(exp(sqrt(-1)*k0'*z)-exp(-1/2));
k1=kv*[cos(pi/4) sin(pi/4)]';
psi1(x,y)=norm(k1)^2*exp(-norm(k1)^2*norm(z)^2/2)*...
(exp(sqrt(-1)*k1'*z)-exp(-1/2));
k2=kv*[cos(pi/2) sin(pi/2)]';
psi2(x,y)=norm(k2)^2*exp(-norm(k2)^2*norm(z)^2/2)*...
(exp(sqrt(-1)*k2'*z)-exp(-1/2));
k3=kv*[cos(3*pi/4) sin(3*pi/4)]';
psi3(x,y)=norm(k3)^2*exp(-norm(k3)^2*norm(z)^2/2)*...
(exp(sqrt(-1)*k3'*z)-exp(-1/2));
end
end
G0=imag(psi0);
G1=imag(psi1);
G2=imag(psi2);
G3=imag(psi3);
f0=conv2(G0,I);f0=f0(1:m,1:n);
f1=conv2(G1,I);f1=f1(1:m,1:n);
f2=conv2(G2,I);f2=f2(1:m,1:n);
f3=conv2(G3,I);f3=f3(1:m,1:n);
GTP0=3^0*(-(f0<-t)+2*(f0>t));
GTP1=3^1*(-(f1<-t)+2*(f1>t));
GTP2=3^2*(-(f2<-t)+2*(f2>t));
GTP3=3^3*(-(f3<-t)+2*(f3>t));
figure,
subplot(2,2,1),imshow(GTP0)
subplot(2,2,2),imshow(GTP1)
subplot(2,2,3),imshow(GTP2)
subplot(2,2,4),imshow(GTP3)
GTP=GTP0+GTP1+GTP2+GTP3;
figure, imshow(GTP)

Más respuestas (1)

NM
NM el 23 de Ag. de 2015
Editada: NM el 23 de Ag. de 2015
Hello, have u apply this algorithm in any areas ?how the result and which paper your refer to code this algorithm?thanks.

Preguntada:

el 22 de Oct. de 2014

Editada:

NM
el 23 de Ag. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by