matlab - How to get the threshold value of k-means algorithm that is used to binarize the images? -


i applied k-means algorithm segmenting images. used built in k-means function. works want know threshold value converts binary images in k-means method. example, can threshold value using built in function in matlab:

threshold=graythresh(grayscaledimage); a=im2bw(a,threshold); %applying k-means.... imdata=reshape(grayscaledimage,[],1); imdata=double(imdata); [imdx mn]=kmeans(imdata,2); imidx=reshape(imdx,size(grayscaledimage)); imshow(imidx,[]); 

actually, k-means , known otsu threshold binarizing intensity images based on global threshold have interesting relationship:

http://www-cs.engr.ccny.cuny.edu/~wolberg/cs470/doc/otsu-kmeanshis09.pdf

it can shown k-means locally optimal, iterative solution same objective function otsu, otsu globally optimal, non-iterative solution.

given greyscale intensity data, 1 compute threshold based on otsu, can expressed in matlab using graythresh, or otsuthresh, depending on interface prefer.

a = imread('cameraman.tif'); = im2double(a); totsu = otsuthresh(histcounts(a,10000)) [~,c] = kmeans(a(:),2,'replicates',10); tkmeans = mean(c) 

you can obtain grayscale threshold kmeans finding midpoint of 2 centroids, should make sense geometrically since on either side of midpoint, closer 1 of centroids or other, , should therefore lie in respective cluster.

totsu =      0.3308   tkmeans =      0.3472 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -