clear all;
close all;

lena_face = imread('lena.jpg');
imshow(lena_face);

figure;
[n, xnum] = imhist(lena_face);
plot(xnum,n)

k = 1;
for i = 1:size(n,1)-1     %A 2 x 2 matrix representing bins and frequencies is formed as a input 
    if n(i) == 0 & flag == 0 %for discrete curve evolution which gives us where the split occurs.
        continue
    end
    A(k,1) = xnum(i);
    A(k,2) = n(i);
    A(k,3) = xnum(i+1);
    A(k,4) = n(i+1);
    k = k+1;
    flag = 1;
end
A(k,1) = A(k-1,3);
A(k,2) = A(k-1,4);

answer = evo2_lena(A) %The output answer has the six points in the image where split occurs

answer = sort(answer);
colour = [255,204,153,102,51];

for i = 1:size(answer,2)
    if i == 1       
        [imageRows, imageCols] = find(lena_face <= answer(i));
        
        for tempCount=1:size(imageRows,1)                
            lena_face(imageRows(tempCount),imageCols(tempCount)) = colour(i); 
        end
    else    
        [imageRows, imageCols] = find((lena_face <= answer(i)) & (lena_face > answer(i-1)));   
       
        for tempCount=1:size(imageRows,1)                
            lena_face(imageRows(tempCount),imageCols(tempCount)) = colour(i); 
        end
    end
    figure;
    imshow(lena_face);
end 

