clear all;
close all;

girl_pic = imread('girl2.jpg');
imshow(girl_pic);

%figure;
[n1, xnum1] = imhist(girl_pic(:,:,1));
%imhist(girl_pic(:,:,1));

%figure;
[n2, xnum2] = imhist(girl_pic(:,:,2));
%imhist(girl_pic(:,:,2));

%figure;
[n3, xnum3] = imhist(girl_pic(:,:,3));
%imhist(girl_pic(:,:,3));


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

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


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

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

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

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

answer1 = sort(answer1)
answer2 = sort(answer2)
answer3 = sort(answer3)
colour = [255,212,169,126,83,43];

for i = 1:size(answer1,2)
    if i == 1
        [imageRows, imageCols] = find(girl_pic(:,:,1) <= answer1(i));
        for tempCount=1:size(imageRows,1)                
            girl_pic(imageRows(tempCount),imageCols(tempCount),1) = colour(i); 
        end
    else
        clear imageRows, imageCols;
        [imageRows, imageCols] = find(girl_pic(:,:,1) > answer1(i-1) & girl_pic(:,:,1) <= answer1(i));
        for tempCount=1:size(imageRows,1)                
            girl_pic(imageRows(tempCount),imageCols(tempCount),1) = colour(i); 
        end
    end
end

for i = 1:size(answer2,2)
    if i == 1
        clear imageRows, imageCols;
        [imageRows, imageCols] = find(girl_pic(:,:,2) <= answer2(i));
        for tempCount=1:size(imageRows,1)                
            girl_pic(imageRows(tempCount),imageCols(tempCount),1) = colour(i); 
        end
    else
        clear imageRows, imageCols;
        [imageRows, imageCols] = find(girl_pic(:,:,2) > answer2(i-1) & girl_pic(:,:,2) <= answer2(i));
        for tempCount=1:size(imageRows,1)                
            girl_pic(imageRows(tempCount),imageCols(tempCount),2) = colour(i); 
        end
    end
end

% for i = 1:size(answer3,2)
%     if i == 1
%         clear imageRows, imageCols;
%         [imageRows, imageCols] = find(girl_pic(:,:,3) <= answer3(i));
%         for tempCount=1:size(imageRows,1)                
%             girl_pic(imageRows(tempCount),imageCols(tempCount),1) = colour(i); 
%         end
%     else
%         clear imageRows, imageCols;
%         [imageRows, imageCols] = find(girl_pic(:,:,3) > answer3(i-1) & girl_pic(:,:,3) <= answer3(i));
%         for tempCount=1:size(imageRows,1)                
%             girl_pic(imageRows(tempCount),imageCols(tempCount),3) = colour(i); 
%         end
%     end
% end

figure;
imshow(girl_pic);   