1.使用imhist()函数求图片直方图的时候,如果是RGB彩色图,则要首先调用rgb2gray()函数将其转化为灰度图。
eg:
1 ImageData=imread(‘baby.jpg‘); 2 I=rgb2gray(ImageData ); 3 figure(1); 4 subplot(2,1,1); 5 imshow(ImageData); 6 subplot(2,1,2); 7 imshow(I); 8 figure(2); 9 imhist(uint8(I) );
执行结果如下:


2.bar可以用作绘制条状图、stem()函数绘制杆状图、plot()函数用来绘制图像最常见。
1 ImageData=imread(‘baby.jpg‘); 2 f=rgb2gray(ImageData ); 3 figure(1); 4 imhist(f); %最原始的结果 5 6 figure(2); 7 h = imhist(f,25); 8 horz = linspace(0,255,25); 9 bar(horz,h) %条形统计图 10 axis([0 255 0 60000] ) 11 set(gca,‘xtick‘,0:50:255) 12 set(gca,‘ytick‘,0:20000:60000) 13 14 figure(3); 15 stem(horz,h,‘fill‘); %杆状图 16 axis([0 255 0 60000]) 17 set(gca,‘xtick‘,0:50:255) 18 set(gca,‘ytick‘,0:20000:60000) 19 20 figure(4); 21 plot(imhist(f)); 22 axis([0 255 0 15000]) 23 set(gca,‘xtick‘,0:50:255) 24 set(gca,‘ytick‘,0:20000:60000)
结果如下图:




原文:http://www.cnblogs.com/liugl7/p/5294114.html