翻翻过去那场雪
描述颗粒形貌边界的分形维数matlab程序: im=imread('e:\4.bmp');imshow(im);gr=im;level = graythresh(gr);figure,imshow(gr);bw=im2bw(gr,0.5);%bw= bwperim(bw);%bw=~bw;figure,imshow(bw); bw=edge(bw,'canny'); figure,imshow(bw); si=size(bw); minblock=1; maxblock=16; flag=0; n=linspace(0,0,maxblock-minblock+1); for k=minblock:maxblock for y=1:k:si(2)-k for x=1:k:si(1)-k flag=0; for y1=y:y+k-1 for x1=x:x+k-1 if bw(x1,y1)==1 flag=1; end; end; end; if flag==1 n(k-minblock+1)=n(k-minblock+1)+1; end; end; end; end; aa=[minblock:maxblock]; xx1=-log(aa); yy1=log(n); a=polyfit(yy1,xx1,1); x=polyval(a,yy1); figure,plot(xx1,yy1,'k+',x,yy1,'r'); D=1/a(1);