function D=genFrctalDimension(img)
%get the fractal dimension of img
[m,n]=size(img);
Ur1=img;
Br1=img;
Ur=img;
Br=img;
count=100;
arrayV=zeros(1,count);
arrayR=zeros(1,count);
for point=1:count
for i=1:m
for j=1:n
roundMax=0;
roundMin=65536;
for p=-1:1
for q=-1:1
px=min(max(i+p,1),m);
py=min(max(j+q,1),n);
roundMax=max(roundMax,Ur1(px,py));
roundMin=min(roundMin,Br1(px,py));
end
end
Ur(i,j)=max(Ur1(i,j)+1,roundMax);
Br(i,j)=min(Br1(i,j)+1,roundMin);
end
end
V=0.5*(sum(sum(Ur-Ur1))+sum(sum(Br-Br1)));
arrayV(point)=log2(V);
arrayR(point)=log2(point);
Ur1=Ur;
Br1=Br;
end
D=polyfit(arrayR,arrayV,1);
D=D(1)-2;