% Image segmentation using clustering in color space
% Name is the name of the image file, number is the number of clusters

function segmentation(name)
global clusterId label im2 eps minpts hr vr cr

im = imread(name);
im = im(40:60, 60:80, :);

figure; imshow(uint8(im));

im = double(im);
[r, c, k] = size(im);

% To determine the radius of the circle in spatial space
eps = ceil(r*c/50);
minpts = (pi*eps^2)/4;

% Noise = 1000;
clusterId = 1;

% Convert RGB to HVC
im2 = RGB2HVC(im);

% Get the radius of HVC.
[hr, vr, cr] = get_radius(im2);

% Initialize the label matrix
for i = 1 : r
    for j = 1 : c
        label(i, j) = -1;
    end
end

% Beging DBScan

[r, c, k] = size(im2);
for i = 1:r
    for j = 1:c
	    if (label(i,j) == -1)
            if (expandcluster([i, j]) == 1) 
                clusterId = clusterId + 1;
            end    
        end
    end
end

save label;

show_segmentation(im);
