# My question is regarding classifying the images based on the whichever color is present more in the given image after converting the color image into gray and finding its histogram.

조회 수: 1(최근 30일)
clc;
figure
imshow(Image);
I=rgb2gray(Image);
figure
imshow(I)
[count,x] = imhist(I)
index1 = find(x == 67);
index2 = find(x == 100);
numPixels = sum(count(index1:index2))
This code worked well up to finding the sum of number of pixels from one intensity range to other.
Now I am having few images. Some of them have red pixels in large amounts,some have white, some have blue, etc. I have to classify these images as blue, white, red, etc. after finding histogram and counting pixels in certain range. How can I do that?
Or is there any other way to do this classification?

### 채택된 답변

Image Analyst 3 Dec 2016
You just need to set up some rules, like if the mean red count from the histogram is more than the mean blue and green counts. See my File Exchange for color demos. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

#### 댓글 수: 9

표시 이전 댓글 수: 6
snehal jaipurkar 7 Dec 2016
??? Undefined function or method 'atan2d' for input arguments of type 'double'.
Error in ==> matlabgrp1 at 15 averageHueAngle = atan2d(sumsin, sumcos) % Compute mean hue angle
this error is shown sir for the code which is sent last time. and i am using 2010 version sir...and u had sent me this code: hsvImage = rgb2hsv(rgbImage); hueImage = hsvImage(:,:,1); sumsin = sum(sind(hueImage (:))) % Use (:) if you want to be able to handle 2-D hue images. sumcos = sum(cosd(hueImage (:))) averageHueAngle = atan2d(sumsin, sumcos) % Compute mean hue angle
i added dis only. but error as such (??? Undefined function or method 'atan2d' for input arguments of type 'double'. ) is shown sir...
Image Analyst 7 Dec 2016
Did you see where I said " it was released way back in 2012 but maybe you have an ancient version of MATLAB." Well, 2010 is 2 years before atan2d was released. You'll have to see how you can build it yourself with atan() or atand(). Search the Mathworks web site for the description of atan2d().
snehal jaipurkar 7 Dec 2016
Ok sir...I vl try to do that if I can get proper results by using atand( )... Thanks a lot for u help sir...