matlab 直方图

本文介绍了如何使用MATLAB进行灰度图像和彩色图像的直方图分析,包括提取RGB各通道分量并绘制对应的直方图,对于图像处理初学者来说是一个很好的实践案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1)灰度直方图

imhist(I)
imhist(I, n) n灰度级数目 默认等于256
[counts, x]=imhist(…) counts为直方图的数据向量,counts(a)表示第a个区间像素数目,x保存了对应的小区间的向量,stem(x,counts/m/n)表示直方图概率。

(2)彩色图像直方图

i=imread('theatre.jpg');

[x,y,z]=size(i);
figure
subplot(221), imshow(i);
title('original image')
%提取红色分量
r=i;
%r(:,:,1)=a(:,:,1);
r(:,:,2)=zeros(x,y);
r(:,:,3)=zeros(x,y);
r=uint8(r);
subplot(222),imshow(r);
title('R-component-image')
%提取绿色分量
g=i;
g(:,:,1)=zeros(x,y);
%g(:,:,2)=a(:,:,2);
g(:,:,3)=zeros(x,y);
g=uint8(g);
subplot(223),imshow(g);
title('G-component-image')
%提取蓝色分量
b=i;
b(:,:,1)=zeros(x,y);
b(:,:,2)=zeros(x,y);
%b(:,:,3)=a(:,:,3);
b=uint8(b);
subplot(224),imshow(b);
title('B-component-image')

或者

i=imread('theatre.jpg');
r=a(:,:,1);
g=a(:,:,2);
b=a(:,:,3);
subplot(1,3,1), imhist(r), title('R component');
subplot(1,3,2), imhist(g), title('G component');
subplot(1,3,3), imhist(b), title('B component');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值