how to find the mean colour

6 views (last 30 days)
kash
kash on 18 May 2013
I have a image which consists of water ,green land and roads,I want to find mean of each colour say blue region ,green region etc
kindly help
  2 Comments
Jan
Jan on 18 May 2013
What have you tried so far? Which toolboxes and experiences do you have?
kash
kash on 18 May 2013
i have image processing toolbox and others tool boxes,i tried doing segmentation and clustering the image into 4 clusters,after that i dont know who to assign colour for it

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 18 May 2013
First you have to classify the image into the 3 categories. Then for each category, you have to mask the original image and measure the mean for pixels in that category. See my File Exchange for color classification demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
  3 Comments
Image Analyst
Image Analyst on 18 May 2013
You can use those to classify images into a limited number of colors. Or try rgb2ind() or kmeans().
kash
kash on 24 May 2013
I have uploaded two images
my code
clc
clear all
close all
he = imread('3.jpg');
K1=[0 0 1];K2=[0 0.8 0];K3=[1 0 0];K4=[1 0 1];
lab_he=rgb2hsv(he);
ab=double(he);
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,3);
nColors = 4;
C=double(he(1:4,1:3));
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',1,'start',C);
segmented_images = cell(1,3);pixel_labels = reshape(cluster_idx,nrows,ncols);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:4
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
figure,imshow(segmented_images{1}), title('objects in cluster 1');
figure,imshow(segmented_images{2}), title('objects in cluster 2');
figure,imshow(segmented_images{3}), title('objects in cluster 3');
figure,imshow(segmented_images{4}), title('objects in cluster 3');
figure,imshow(he)
figure,imshow(ind2rgb(pixel_labels, [K2;K1;K3;K4]))
Mean1=mean(mean(segmented_images{1}(:)))
Mean2=mean(mean(segmented_images{2}(:)))
Mean3=mean(mean(segmented_images{3}(:)))
Mean4=mean(mean(segmented_images{4}(:)))
I like to colour water portion in red ,green portion in blue etc
so i made 4 clusters,wen i took the mean of each cluster for water portion the value is different for those two images,please tell how to compute the water colour which must be same for two images,omly ten it is poosible to assign red colour for it

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!