写了一个输入图片,便会生成美观的图像各通道亮度分布图的函数,大概效果如下:
老样子,工具函数放在最前面,之后会介绍咋用这个函数:
工具函数
function histogrampic(pic) freqnum=zeros(size(pic,3),256); for i=1:size(pic,3) for j=0:255 freqnum(i,j+1)=sum(sum(pic(:,:,i)==j)); end end ax=gca;hold(ax,'on');box on;grid on if size(freqnum,1)==3 bar(0:255,freqnum(1,:),'facecolor',[0.6350 0.0780 0.1840],'facealpha',0.5); bar(0:255,freqnum(2,:),'facecolor',[0.2400 0.5300 0.0900],'facealpha',0.5); bar(0:255,freqnum(3,:),'facecolor',[0 0.4470 0.7410],'facealpha',0.5); ax.xlabel.string='rgb brightness'; rrange=[num2str(min(pic(:,:,1),[],[1,2])),' , ',num2str(max(pic(:,:,1),[],[1,2]))]; grange=[num2str(min(pic(:,:,2),[],[1,2])),' , ',num2str(max(pic(:,:,2),[],[1,2]))]; brange=[num2str(min(pic(:,:,3),[],[1,2])),' , ',num2str(max(pic(:,:,3),[],[1,2]))]; legend({['r: range[',rrange,']'],['g: range[',grange,']'],['b: range[',brange,']']},... 'location','northwest','color',[0.9412 0.9412 0.9412],... 'fontname','cambria','linewidth',0.8,'fontsize',11); else bar(0:255,freqnum(1,:),'facecolor',[0.50 0.50 0.50],'facealpha',0.5); ax.xlabel.string='gray scale'; krange=[num2str(min(pic(:,:,1),[],[1,2])),' , ',num2str(max(pic(:,:,1),[],[1,2]))]; legend(['gray: range[',krange,']'],... 'location','northwest','color',[0.9412 0.9412 0.9412],... 'fontname','cambria','linewidth',0.8,'fontsize',11); end ax.linewidth=1; ax.gridlinestyle='--'; ax.xlim=[-5 255]; ax.xtick=[0:45:255,255]; ax.ylabel.string='frequency number'; ax.fontname='cambria'; ax.fontsize=13; end
函数调用
非常简单的使用方法,就是读取图片后调用函数即可:
pic=imread('test.png'); histogrampic(pic)
若图像是彩图则效果如下:
若图像为灰度图则效果如下:
以上就是利用matlab实现图像亮度分布统计图的详细内容,更多关于matlab亮度分布统计图的资料请关注<计算机技术网(www.ctvol.com)!!>其它相关文章!
需要了解更多c/c++开发分享利用Matlab实现图像亮度分布统计图,都可以关注C/C++技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/1246765.html