Write a python script/function, that realizes color segmentation of and image using the k-means method. Use the image 'bricks.png' from the data section.
The algorithm:
- initialize k random seeds - color etalons (three-dimensional RGB vectors)
- assign every pixel to one of the etalons (minimal euclidean distance in RGB space)
- recompute every etalon as a mean of all assigned pixels
- compute the change of every etalon (euclidean distance between the last and current one)
- if the change of every etalon is bellow threshold, or max. number of iterations reached, terminate
- otherwise repeat from step 2
Use k=5, max. iterations=100, change threshold 0.0001 (when pixel colors are in range 0-1).