Matlab实现RGB和HSV直方图处理

RGB彩色图像的直方图均衡化处理

function Histogramequalization()
[f,p]=uigetfile('*.*','选择图像文件');
if f
I=imread(strcat(p,f));
end

Ir=I(:,:,1);%提取红色分量
Ig=I(:,:,2);%提取绿色分量
Ib=I(:,:,3);%提取蓝色分量
R=double((I(:,:,1)))/255;
G=double((I(:,:,2)))/255;
B=double((I(:,:,3)))/255;
figure;
subplot(1,3,1),imshow(R);
subplot(1,3,2),imshow(G);
subplot(1,3,3),imshow(B);
I1=histeq(Ir);   %直方图均衡化函数histeq
I2=histeq(Ig);
I3=histeq(Ib);
c=cat(3,I1,I2,I3);  %cat用于构造多维数组
figure;
subplot(1,2,1);imshow(I);
title('A). 原始图像');  
subplot(1,2,2);imshow(c);
title('B). 直方图均衡化');
figure;
subplot(1,3,1);
imhist(Ir);
title('I). 红色分量直方图');
subplot(1,3,2);
imhist(Ig);
title('I). 绿色分量直方图');
subplot(1,3,3);
imhist(Ib);
title('I). 蓝色分量直方图');
figure;
subplot(1,3,1);
imhist(I1);
title('II). R均衡化后直方图');
subplot(1,3,2);
imhist(I2);
title('II). G均衡化后直方图');
subplot(1,3,3);
imhist(I3);
title('II). B均衡化后直方图');

结果展示
在这里插入图片描述
将RGB转为HSV通道进行直方图处理

close all;
%RGB=imread('F:\code\31.png');
[f,p]=uigetfile('*.*','选择图像文件');
if f
RGB=imread(strcat(p,f));
end
HSV=rgb2hsv(RGB);
H=HSV(:,:,1);
S=HSV(:,:,2);
V=HSV(:,:,3);

figure;
subplot(1,3,1),imhist(H);
title('I). H分量直方图');
subplot(1,3,2),imhist(S);
title('I). S分量直方图');
subplot(1,3,3),imhist(V);
title('I). V分量直方图');
H=histeq(H);
figure,imhist(H);
title('II). H均衡化后直方图');
S=histeq(S);
figure,imhist(S);
title('II). S均衡化后直方图');
V=histeq(V);
figure,imhist(V);
title('II). V均衡化后直方图');
HSV(:,:,1)=H;
HSV(:,:,2)=S;
HSV(:,:,3)=V;
RGB_1=hsv2rgb(HSV);
figure;
subplot(1,2,1),imshow(RGB);
title('A). 原始图像');  
subplot(1,2,2),imshow(RGB_1);
title('B). 直方图均衡化');

结果展示
在这里插入图片描述

  • 16
    点赞
  • 98
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值