Introduction

Using k means for k =4 or 5

separate pixels into 5 categories: cyan, magenta, yellow, black, and white.

OR: separate pixels into 4 categories: cyan, magenta, yellow, and white. (since some of do not have black cluster)

filtering procedure

1. Separate all pixels based on the color into colorants. 2. separate pixels into categories: cyan, magenta, yellow, black, and white. 3. get some preliminary statistical results.


matlab code

close all clc clear

%step one---Seperate the colorant of picture

picture = imread('CA230(5).bmp'); [x,y,z] =size(picture);

%!!!in lab color space is better for kmeans % WORKING IN LAB SPACE imglab = rgb2lab(picture); data = double (reshape(imglab,x*y,z)); k = 4; [index] = kmeans(data, k);


out_c = uint8(reshape(index,x,y));

figure(1); imagesc(out_c); title('kmeans output');

figure(2); imshow(picture); title('original image')


%step 2------mask the dots %Put different cluster into seperate 2D matrix newmap = zeros(size(picture));

figure(3) bwmap = zeros(size(picture,1), size(picture,2),4);

for label = 1 : k

   for i = 1: size(out_c,1)
       for j = 1: size(out_c,2)
           if out_c(i,j) == label
               newmap(i,j,:) = picture(i,j,:);
               bwmap(i,j,label) = 1;
           else
               newmap(i,j,:) = 0;
               bwmap(i,j,label) = 0;
           end
       end
   end
   subplot(3,2,label)
   title('extracted layer from k clusters')
   imshow(uint8(newmap))

end




label = 0; for label = 1:k

   CCstruct = bwconncomp(bwmap(:,:,label),8);
   
   %CCdots = CCstruct.PixelIdxList;
   
   CCnumPixels = cellfun(@numel,CCstruct.PixelIdxList);
   
   
   
   
   %find the connected conponents with numPixel greater than 10
   %sort(numPixels,'descend')
   
   %size
   %=====----count the elements bigger than 10
   %set 10 as treshold
   CCbigcon{label} = (sum(CCnumPixels > 10))
   
   
   %standard deviation
   %=====----count the standard deviation for elements bigger than 10
  
   CCstd{label} = std(CCnumPixels)
   
   %maximum
   %=====----find the max num of pixels for each colorant
   CCmax{label} = max(CCnumPixels)
       
   %total number of pixel of each cluster 
   %=====----find the max num of pixels for each colorant
   %CCtotal = zeros(label);
   %CCtotal(label) = sum(CCnumPixels)
   
   %average LAB color space value for connected component of each cluster
   
   %average RGB color space value for connected component of each cluster
      

end

%CCdata = ([1:1:label],[cell2mat(CCbigcon)],[cell2mat(CCstd)],[cell2mat(CCmax)])


% you can compute statistics for each colorant % area, number of dots, size ..., maximum, minimum, %you can also cimpute the average lab value for each color/label/dot/colorant %average rgb, standard deviation of lab

results

1. Separate all pixels based on the color into colorants. separate pixels into categories: cyan, magenta, yellow, black, and white. Pseudo color for the k = 4 clusters

white cyan magenta

yellow


2. If you accomplish first 2 steps then we can get some preliminary statistical results, such as area and number of components.


With order of cluster one to cluster four, which is from (white, cyan ,magenta to yellow) %size

   %=====----count the elements bigger than 10
   %set 10 as treshold

CCbigcon =

   [3]    [220]    [146]    [218]

%standard deviation

   %=====----count the standard deviation for elements bigger than 10

CCstd =

   [7.0742e+04]    [94.1128]    [91.2085]    [93.4776]



%maximum

   %=====----find the max num of pixels for each colorant

CCmax =

[685870] [306] [262] [318]

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood