function fd = mmfractal( f, range, option ) % MMFRACTAL Compute the fractal dimension of a binary image using Minkowski sausage model. % % FD = MMFRACTAL( F, RANGE, OPTION ) % % Input: % F - Binary image (logical uint8). % RANGE - Gray-scale (uint8 or uint16) or binary image (logical % uint8). Vector with linearly increasing radius of the disk % used in the dilation. Selects to portion to use the fitting % in determine the line slope. % OPTION - String. optionally show plot to visualize the slope. ' % PLOT' or 'NOPLOT'. DEFAULT: 'PLOT'. % % Output: % FD - Fractal dimension. % % Measures the natural logarithm decay of the area of the dilation % minus erosion divided by the diameter of the Euclidean disk used % in the dilation. The range sets the minimum and maximum diameter % where the fitting is made. The plot of the fitting is shown. % % Examples % -------- % % f1=mmreadgray('gear.tif'); % mmshow(f1); % fd1=mmfractal(f1,[5:15]) % showfig(slope_fd1); % f2=mmopen(f1,mmsedisk(2)); % mmshow(f2); % fd2=mmfractal(f2,[5:15]) % showfig(slope_fd2); % % begin of the default argument automatic treatment if ~exist('option','var') option = 'PLOT'; end % end of the default argument automatic treatment 1 g=mmgradm(f); d=mmdist(mmneg(g),mmsebox,'euclidean'); h=double(mmhistogram(d)); hacc=cumsum(h)'; xall=1:length(h); yall=hacc(xall)./(2*xall); x=log(range); y=log(hacc(range)./(2*range)); [p s]=polyfit(x,y,1); % p(1) is the inclination if strcmp(upper(option),'PLOT') plot(log(xall),log(yall),'.-',x,polyval(p,x),'r');figure(gcf); end fd=-(-1+p(1)); % Copyright (c) 1998-2001 by SDC Information Systems.