Simple_Fractal_Dimension_for_Images.m
上传用户:makun0805
上传日期:2013-12-24
资源大小:1k
文件大小:1k
源码类别:
分形几何
开发平台:
Matlab
- function Simple_Fractal_Dimension_for_Images(xyimg)
- % Input: xyimg is image with 256*256
- yyimg=im2bw(xyimg,0.5);
- xximg=~yyimg;
- for ii=0:7
- e(ii+1)=2^ii;
- ne(ii+1)=0;
- cboxs=256/e(ii+1);
- for i=1:cboxs
- xi=(i-1)*e(ii+1)+1;
- for j=1:cboxs
- yi=(j-1)*e(ii+1)+1;
- ne_tp=0;
- for xk=xixi+e(ii+1)-1)
- for yk=yiyi+e(ii+1)-1)
- if xximg(xk,yk)==0
- ne_tp=1;
- end
- end
- end
- if ne_tp==1
- ne(ii+1)=ne(ii+1)+1;
- end
- end
- end
- end
- elog=log(256./e);
- nelog=log(ne);
- c=polyfit(elog,nelog,1);
- sfd=c(1);
- xx=min(elog):0.1:max(elog);
- yy=c(1).*xx+c(2);
- subplot(1,2,1);
- imshow(xyimg);
- subplot(1,2,2);
- plot(elog,nelog,'+:',xx,yy,'-');
- grid;
- xlabel('log(e)');
- ylabel('log(N(e))');
- title(['Fractal Dimension: Df is ' num2str(sfd,'%11.5g')]);
- axis([0 6 0 10]);