% regionQuery - Region growing, to find homogeneous pixels not only in
% color space, but also in spatial space
% It will return a set of pixels which are homogeneous to the specific
% point

function seed = regionQuery(point)
global clusterId label im2 eps minpts hr vr cr

[r, c, k] = size(im2);

i = point(1);
j = point(2);

topleft_i = max(i-eps, 1);
topleft_j = max(j-eps, 1);
rightbottom_i = min(r, i+eps);
rightbottom_j = min(c, j+eps);

seed = [i, j];

for temp_i = topleft_i : rightbottom_i
    for temp_j = topleft_j : rightbottom_j
        % To see if this pixel is the circle of point (i, j)
        if spatial_distance(temp_i, temp_j, i, j) < eps
            % To see if the pixel is in the ellipsoid of point(i, j) in the
            % color space
            if color_distance(temp_i, temp_j, i, j) < 1
                if ((temp_i ~= i) | (temp_j ~= j))
                    seed = [seed;[temp_i, temp_j]];
                end
            end
        end
    end
end
