1. The simple version is an algorithm with simple bin partioning:

The four subroutines are: mfs.m, mfsAll.m and mfsRefine.m,



a) mfs.m: estimates a single MFS vector given an image, where the image
                 can be either a gray-scale image, or the image of some filter-outputs.

parameters: ind_num -> determines how many levels are used when computing the density:
                       with 1 (default) the image is used directly (no density estimation)
                       use >= 6 to compute the density of the image  (which is the change of image over scale)    
            f_num----> determines the dimension of initial MFS estimation.
            ite_num -> determines how many levels are used when computing MFS for each level set

b) mfsAll.m: estimates the combined MFS vector, which is composed of three types: intensity, gradients and laplacian.


c) mfsRefine.m: Refines the MFS vector.
                This function selects a subset of the three fractal dimension vectors and weights each vector
                to obatin a combined vector. We found experimentally, which components of the MFS vectors are useful.
                Ideally, one should learn which parts to use, for example by using a SVM. 

Parameters: weight --> determines the importance of the individual  MFS  measurements
            idx --> The index of reliable elements in initial MFS
                   idx{1} --> intensity
                   idx{2} --> gradients
                   idx{3} --> laplacian
d.) mfs_dist.m : Computes the L1 distance between two mfs vectors


%%Compute the MFS for a given image "exposed_brickwork.jpg'

im = imread ('exposed_brickwork.jpg');
im = rgb2gray(im);
MFS = mfs(im)  %%%%%% computes a single MFS vector based on intensity
or
MFS = mfs(im, 6)  computes a single MFS vector based on the density of the intensity

To compute the refined 3 component MFS vectors  
im1 = imread ('exposed_brickwork.jpg');
MFSA1 =mfsAll(im1)   %%%%% computes a vector consisting of three MFS vectors (intensity, derivatives, laplacian)
MFSA1r= mfsRefine(MFSALL1)        %%%%%%%  picks up the robust measurements and assigns a weight to each of the 
                                        3 MFS measurements (intensity, derivative,laplacian)

%% Compare 2 refined MFS vectors

im1 = rgb2gray(im1);
MFSA1 = mfsAll(im1);
MFSA1r= mfsRefine(MFSA1); 

im2 = imread ('water_stained_brick.jpg');
MFSA2 =mfsAll(im2);  
MFSA2r= mfsRefine(MFSA2); 

dist = mfs_dist(MFSA1r, MFSA2r)


2. A second version is an algorithm with complicated k-mean based bin partitioning. 

Code: There are four subroutines: mfs_kmean.m, mfsAll_kmean.m,  mfsRefine_kmean.m and mfs_dist_kmean.m

The settings are the same as for the simple algorithm.


Examples:


%%Compute the k_mean clustered MFS for a given image "exposed_brickwork.jpg'

im = imread ('exposed_brickwork.jpg');
im = rgb2gray(im);
[alpha,MFS] = mfs_kmean(im)  %%%%%% computes a single MFS vector based on intensity

To compute the refined 3 component MFS vectors  
im1 = imread ('exposed_brickwork.jpg');
[a1,MFSA1] =mfsAll_kmean(im1)   %%%%% computes a vector consisting of three MFS vectors (intensity, derivatives, laplacian)
[a1r,MFSA1r]= mfsRefine_kmean(a1,MFSA1)        %%%%%%%  picks up the robust measurements and assigns a weight to each of the 
                                        3 MFS measurements (intensity, derivative,laplacian)

%% Compare 2 refined k_mean clustered MFS vectors

im1 = rgb2gray(im1);
[a1,MFSA1] = mfsAll_kmean(im1);
[a1r,MFSA1r]= mfsRefine_kmean(a1,MFSA1); 

im2 = imread ('water_stained_brick.jpg');
[a2,MFSA2] = mfsAll_kmean(im2);  
[a2r,MFSA2r]= mfsRefine_kmean(a2,MFSA2); 

dist = mfs_dist_kmean(a1r,MFSA1r,a2r, MFSA2r)  % computes the Earth mover's distance




