#### jothiseetha

##### Newbie level 1

i m trying the project edge detection using hidden markov chain(HMC) model based on wavelets.The HMC needs transition matrix(TM), initial state probability (PI)distribution,observation sequence(O),and observation pobability distribution(b).

for my case the observation(O) is wavelet coefficients.

TM=[.95 .05;.2 .8];

PI[.5 .5];

b= can be achieved through gaussion and laplacian pdf;

while executing my program i am receiving the following error.

??? Attempted to access b(1,0.5); index must be a positive integer or logical.

Error in ==> pr_hmm at 13

m(1,i)=b(i,o(1))*pi(i);[/size][/b][/color][/size]

Code:

```
clc;
clear all;
close all;
X=imread('cameraman.tif');
%SWT
[a1,h1,v1,d1] = swt2(X,1,'haar');
[a2,h2,v2,d2] = swt2(a1,1,'haar');
[a3,h3,v3,d3] = swt2(a2,1,'haar');
w=[a3,h3;v3,d3];
w=w(:)';
k=1;
for i=1:256
for j=1:256
seq1(k,1:3)=[h1(i,j),v1(i,j),d1(i,j)];
k=k+1;
end
end
k=1;
for i=1:256
for j=1:256
seq2(k,1:3)=[h2(i,j),v2(i,j),d2(i,j)];
k=k+1;
end
end
k=1;
for i=1:256
for j=1:256
seq3(k,1:3)=[h3(i,j),v3(i,j),d3(i,j)];
k=k+1;
end
end
e=1;
for k=1:65536
o(e,1:3)=seq1(k,1:3);
e=e+1;
end
w=w(:)';
data1=w;
var1=var(data1);
std1=sqrt(var1);
for k=1:262144
y1(k)=(2*pi*var1).^(-1/2)*exp(-(data1(k).^2)/2*var1.^2);
x1(k)=(2).^(-1/2)*(std1).^(-1)*exp(-(sqrt(2)*data1(k))/std1);
b(k,1:2)=[x1(k),y1(k)];
end
pi=[.5 .5];
a=[.95 .05;.2 .8];
s=pr_hmm(o,a,b,pi);
%%pr_hmm
function p=pr_hmm(o,a,b,pi)
%INPUTS:
%O=Given observation sequence labellebd in numerics
%A(N,N)=transition probability matrix
%B(N,M)=Emission matrix
%pi=initial probability matrix
%Output
%P=probability of given sequence in the given model
n=length(a(1,:));
T=length(o);
%it uses forward algorith to compute the probability
for i=1:n %it is initilization
m(1,i)=b(i,o(1))*pi(i);
end
for t=1:(T-1) %recurssion
for j=1:n
z=0;
for i=1:n
z=z+a(i,j)*m(t,i);
end
m(t+1,j)=z*b(j,o(t+1));
end
end
p=0;
for i=1:n %termination
p=p+m(T,i);
end
```