%% Quanli Wang, Mike West
%quanli@stat.duke.edu

%% MCF Size Filter Example
%load matlab image examples 'pears.png' and convert it to grayscale image

addpath dist

a = imread('pears.png');
b = rgb2gray(a);
figure(1),imshow(b),title('input image');

%Size parameters to be used
theta = [500 17500];

%MCF Size Transform
[X A ] = ImmersionSimulation1(255-b, @ISSO_SizeShapeFilter, @ISSO_agr,theta, []);

%simple thresholding for final segmentation result
result = A>0;

%% Display result 
figure(3), imshow(result,[])

%create fig 1d in the paper
L = bwlabel(A>0);
Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');
figure(4), imshow(Lrgb)

figure(5), imshow(b), hold on
himage = imshow(Lrgb);
set(himage, 'AlphaData', 0.3);
title('Lrgb superimposed transparently on original image')
