Cluster a colour image (number of clusters are user defined) using the
k-means algorithm.
function call:
[out_img1]=vsg('Cluster',in_img1,num1);
Arguments:
in_img1
- input image, 3
channel RGB, 1 channel greyscale or binary image.
num1
– an integer
specifying the number of colours to which the input image shall be
reduced.
Description:
out_img1
– an image with the same dimensions as the input image which is the
input image with a reduced number of colours. The colours are estimated
such that the difference between the input and output images is
minimised.
Example:
in_img1=imread('lake.jpg');
h=figure;image(in_img1);set(h,'Name','Input');
num1=7;
% number of colour clusters
[out_img1]=vsg('Cluster',in_img1,num1);
h=figure; image(uint8(out_img1));set(h,'Name','Cluster');
Clusters may merge
and a lower number of output colours may be found.