To simply choose the K most further apart entities as initial centroids is rather dangerous. Real-world data sets tend to have outliers, under your approach these would be chosen as initial centroids. There are many initialization algorithms for K-Means, perhaps you would like to take a look at intelligent K-Means....

matlab,classification,centroid

xenoclast's answer should be quite clear, just to add something extra. As you are done creating the binary image from the grayscale image of yours using im2bw; if the edge of your the object is a the boundary that covers the object fully, you may use regionprops(bw,'centroid') directly without going...

Three steps: First, find all the cells in each polygon, return a list of 2-column matrices with the cell number and the value: require(plyr) # for llply, laply in a bit... cell_value = extract(dat, polys,cellnumbers=TRUE) head(cell_value[[1]]) cell value [1,] 31 108 [2,] 32 108 [3,] 33 110 [4,] 92 110...

Yes this can happen. It depends on your implementation what is then happening. Some leave the cluster center as is, some reduce k, some choose a new cluster center, some crash badly....

python,audio,centroid,spectral

I have never implemented this before but as far as I understand the Wikipedia formula, it should be something like this: import numpy as np def spectral_centroid(x, samplerate=44100): magnitudes = np.abs(np.fft.rfft(x)) # magnitudes of positive frequencies length = len(x) freqs = np.abs(np.fft.fftfreq(length, 1.0/samplerate)[:length//2+1]) # positive frequencies return np.sum(magnitudes*freqs) / np.sum(magnitudes)...

matlab,image-processing,line,centroid

Here is a file exchange link to bresenham.m Changed your code to get all the 4 centroids %// read your input image im = imread('http://i.stack.imgur.com/xeqe8.jpg'); BW = im>220; CC = bwconncomp(BW); stat = regionprops(CC,'Centroid'); figure; imshow(BW); hold on for x = 1: numel(stat) plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro'); end Here is the output: Further...