Effacer les filtres
Effacer les filtres

write this code in matlab

1 vue (au cours des 30 derniers jours)
faraz.a
faraz.a le 28 Mai 2013
step 1 read the image
then write it in a 2-d array(matrix)
assign i=1 and j=1 (1=rows, j= columns)
assign A(i,j)=X (this is array)
A(i,j-1)=A
A(i-1,j)=B
now give context=AB (which should be 00,01,10,11 any one of them)
if {
context=00
{
if
X=0
{ c0(00)=1+c0(00) }
else if X=1
{ c1(00)=1+c1(00) (at start c1(00) c0(00) all are equal to zero) }
cont(00)=1+cont(00)
}
else if context=01
{ if x= 0
{
c0(01)=1+c0(01)
}
else if X=1
{
c1(01)=1+c1(01)
}
cont(01)=1+cont(01)
}
else if context=10
{
if X=0
{
c0(10)=1+c0(10)
} else if X=1
{
c1(10)=1+c1(10)
}
cont(10)=1+cont(10)
}
else if context=11
{
if X=0 { c0(11)=1+c0(11)
}
else if X=1
{
c1(11)=1+c(11)
}
cont(11)=1+cont(11)
}
if j<256 (size of the image is 256*256 then we should take 256)
{
j=j+1
}
else if j=256
{ i=i+1
} if i=256 && j=256 (both should 256)
end
else go to
{
assign A(i,j)=X (it should go back to this)
} then i have to find out some float values when displaying this it should c0me steady state probabilities p(00)=cont(00)/(total number of counts i think it will be the size of the matrix 256*256)
p(01)=cont(01)/(256*256)
p(10)=count(10)/(256*256)
p(11)=count(11)/(256*256) }
now display these all the below conditional probabilities p0(00)=c0(00)/cont(00)
p1(00)=c1(00)/cont(00)
p0(01)=c0(01)/cont(01)
p1(01)=c1(01)/cont(01)
p0(10)=c0(10)/cont(10)
p1(10)=c1(10)/cont(10)
p0(11)=c0(11)/cont(11)
p1(11)=c1(11)/cont(11)
similarly all the values then h(00)=p0(00)logbase2(1/p0(00)) +p1(00)logebase2(1/(p1(00)
h(01)=p0(01)logbase2(1/p0(01)) +p1(01)logebase2(1/(p1(01)
so onll ti h(11) can we write h(00)= h(AB)?? these 00,01,10,11 are actually AB it is very hard how to write all and display all these assign h(s) entropy= p(AB)H(AB) end the way i wrote in my notes p(00)h(00)+p(01)h(01)+p(10)h(10)+p(11)h(11) display all these values }
  3 commentaires
Jan
Jan le 28 Mai 2013
Do you have a specific question or do you assume that we solve the complete problem for you?
faraz.a
faraz.a le 28 Mai 2013
i know you will not solve i just have questions in between the code i mentioned in comments. new in matlab dont know anything about it so trying to solve step by step

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 28 Mai 2013
Indexes have to be integers like 1, 2, 3, etc. (or logical true/false) - you can't have an index of 00. You'll have to figure that out. And, MATLAB code doesn't use { to start a block, and it uses "end" instead of } to finish a block. Comments begin with a % symbol. I, for one, don't have time to fix your code or translate it into MATLAB code for you. Good luck.
  6 commentaires
faraz.a
faraz.a le 28 Mai 2013
okay
d=imread("coin.tif")
size(d)
fid = fopen('coin.tif','rb'); opens the file
M = fread(fid, [rows columns], 'int16')
M = reshape(M,[r c]);
disp(M)
i00=1
i01=2
i10=3
i11=4
c0(i00)=0,c1(i00)=0,c0(i01)=0,c1(i01)=0,c0(i10)=0,c1(i10)=0,c0(i11)=0,c1(i11)=0 %can i define it this way?
i=1 and j=1 % i=rows, j= columns
for i from 1 to 256 do %(i hope it increments every time)
for j from 1 to 256 do
M(i,j)=X
M(i,j-1)=A
M(i-1,j)=B
if A==0 && B==0
if X=0
c0(i00)=1+c0(i00)
end % do i need to write end over here?
else if X=1
c1(i00)=1+c1(i00)
end
cont(i00)=1+cont(i00)
end
else if A==0 && B==1
if x= 0
c0(i01)=1+c0(i01)
end
else if X=1
c1(i01)=1+c1(i01)
end
cont(i01)=1+cont(i01)
end
else if A==1 && B==0
if X=0
c0(i10)=1+c0(i10)
end
else if X=1
c1(i10)=1+c1(i10)
end
cont(i10)=1+cont(i10)
end
else if A==1 && B==1
if X=0
c0(i11)=1+c0(i11)
end
else if X=1
c1(i11)=1+c(i11)
end
cont(i11)=1+cont(i11)
end
cont=1+cont
end_for
end_for
c0me steady state probabilities
p(i00)= mod(cont(i00),cont)
p(i01)= mod(cont(i01),cont)
p(i10)= mod(cont(i10),cont)
p(i11)= mod(cont(i11),cont)
now display these all the below conditional probabilities p0(i00)=mod(c0(i00),cont(i00))
p1(i00)= mod(c1(i00),cont(i00))
p0(i01)= mod(c0(i01),cont(i01))
p1(i01)= mod(c1(i01),cont(i01))
p0(i10)= mod(c0(i10),cont(i10))
p1(i10)= mod(c1(i10),cont(i10))
p0(i11)= mod(c0(i11),cont(i11))
p1(i11)= mod(c1(i11),cont(i11))
h(i00)= -p0(i00)log2(p0(i00))- p1(i00)log2(p1(i00))
h = p(i00)*h(i00)+p(i01)*h(i01)+p(i10)*h(i10)+p(i11)*h(i11)
end
now will this display all the values or i need to write something to display?
is this the way i need to write in matlab?
faraz.a
faraz.a le 28 Mai 2013
i will execute and ask if i get errors thank you so much for your guidance sir

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by