kmeans help #2

  • Follow


Oct 4, 2011 12:34:23 PM, mona.madhu@yahoo.co.in wrote:

  I need to segment white blood cells using kmeans clustering, so that
I can extract the blue stained nucleus. A sample image is attached
with this mail. My code works, but as it is known, the results vary
with every run. I need to know how to set the kmeans function, such
that every time I run the code, I get my interested area only in one
particular cluster.
Your reply will be of great help.

My code is as follows:

he=mat2gray(imread('image9.jpg'));
%imshow(he), title('H&E image');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx cluster_center] =
kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);

pixel_labels = reshape(cluster_idx,nrows,ncols);
%imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end

ref : http://www.mathworks.com/products/image/demos.html?file=/products/demos/shipping/images/ipexhistology.html

Thank you for your time!
Mona
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Whenever someone complains of failure to reproduce resiults, I
automatically think of RNG intialization.

Try printing out the states of  rand (or whatever RNGs may be
used) before and after each command that might cause it to change.

Hope this helps.

Greg
0
Reply heath (3875) 10/8/2011 11:50:42 PM


0 Replies
68 Views

(page loaded in 0.054 seconds)

Similiar Articles:













7/23/2012 12:23:42 PM


Reply: