- RGB三通道各自直方图
- 对R通道直方图做均衡化处理
- 将G通道直方图规定化到B通道直方图
- 对B通道进行矩形窗高斯滤波处理
matlab代码:
clc
close all
fig=imread('figure_name.jpg'); % 读取图像
imshow(fig);
%% --------------------RGB三通道各自直方图-------------------------
R=fig(:,:,1); %R通道 im(:,:,1) 表示三维图像 第一个参数表示获取全部行
G=fig(:,:,2); %G通道 第二个参数表示获取全部列
B=fig(:,:,3); %B通道 第二个参数表示获取页数
figure(1)
subplot(2,2,1)
histogram(R);
title('R通道直方图');
subplot(2,2,2)
histogram(G);
title('G通道直方图');
subplot(2,2,3)
histogram(B);
title('B通道直方图');
%% ------------------对R通道直方图做均衡化处理-----------------------
R_1=histeq(R); %实现直方图均衡化
figure(2)
subplot(2,2,1)
histogram(R);
title('原图像直方图');
subplot(2,2,2)
histogram(R_1);
title('均衡化后的直方图');
subplot(2,2,3)
imshow(R);
title('原图')
subplot(2,2,4)
imshow(R_1);
title('均衡化后图像');
%% ----------------将G通道直方图规定化到B通道直方图----------------
B_his=imhist(B); %B通道直方图
G_rule=histeq(G,B_his);
figure(3)
subplot(221)
histogram(G);
title('G通道直方图');
subplot(2,2,2)
histogram(G_rule);
title('规定化后G通道直方图');
subplot(2,2,3)
imshow(G);
title('规定化前G通道图像');
subplot(2,2,4)
imshow(G_rule);
title('规定化后G通道图像');
%% ----------------对B通道进行矩形窗高斯滤波处理----------------------
W = fspecial('gaussian',[5,5],1); % 创建滤波器,矩形窗5*5,标准差为1
B_G = imfilter(B, W, 'replicate'); %replicate用数组边界值填充边界外。X用0填充边界
figure(4);
subplot(121);
imshow(B);
title('原始图像');
subplot(122);
imshow(B_G);
title('滤波后图像');