我尝试了以下内容:
b=imread('/home2/s163720/lebron.jpg');
hsv = rgb2hsv(b);
h = hsv(:,:,1);
imhist(h,16)
然而,它并没有让我满意的是我正在寻找的东西。很高兴看到某种类型的计数器用于不同的色调,或者甚至可能是颜色的分布。 非常感谢。
答案 0 :(得分:0)
我知道这应该是答案应该在哪里,但我很确定你的问题没有通用的答案。然而,有几种可能性,也许你或其他任何人都可以拿出更多。
因此,您想要直方图的基本问题是,您必须选择颜色的某种表示形式作为单个数字。这是一个相当困难的问题。
第一种解决方案可能是将rgb颜色转换为波长,然后忽略图像的强度。使用这个想法的问题是rgb颜色定义的颜色多于仅在波长上的颜色。见:http://jp.mathworks.com/matlabcentral/newsreader/view_thread/313712
第二种解决方案可以是将数字定义为A = sum(rgb。* [1,10,100]);然后使用此数字作为颜色的表示。
第三种解决方案是将数字的十六进制表示转换为十进制表示,然后使用此数字。
对每个像素的每种颜色进行表示后,只需将矩阵重新整形为矢量,然后使用标准hist命令绘制它。但如上所述,mayby有更好的想法将颜色表示为单个数字。
答案 1 :(得分:0)
我认为这可能与您正在寻找的内容相符。
%Read the image
img = imread('/home2/s163720/lebron.jpg');
%convert to hsv and reshap to a N x 3 matrix
hsv = rgb2hsv(img);
hsv2 = squeeze(reshape(hsv, [], 1, 3));
%Extract hue (and convert to an angle) and saturation
Hue = 2*pi*hsv2(:,1);
Saturation = hsv2(:,2);
%The number of bins in the hue and saturation directions
RadialColorBins = 50;
AngularColorBins = 50;
%Where the edged of the bins are
edges = {linspace(0, 1, RadialColorBins), linspace(0, 2*pi, AngularColorBins) - 2*pi / AngularColorBins};
%bin the data
[heights,centers] = hist3([Saturation, Hue],'Edges',edges);
%Extract the centers
radius = centers{1};
angle = centers{2};
%Force periodicity
angle = [angle, angle(1)];
heights = [heights, heights(:, 1)]';
%Mesh the r and theta components
[Radius, Angle] = meshgrid(radius, angle);
%Make a color map for the polar plot
CMap = hsv2rgb(Angle/(2*pi), Radius, ones(size(Radius)));
figure(1)
imshow(img)
%polar histogram in s-h space
figure(2)
surf(Radius.*cos(Angle), Radius.*sin(Angle), heights, CMap,'EdgeColor','none');