1. 程式人生 > >直方圖均衡化matlab實現(續)

直方圖均衡化matlab實現(續)

彩色影象直方圖均衡化:

%彩色影象直方圖均衡化matlab
clear
I=imread('12.bmp');%讀取影象
R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);
J(:,:,1)=histeq(R);
J(:,:,2)=histeq(G);
J(:,:,3)=histeq(B);
figure;%顯示原影象和均衡化後的影象
subplot(1,2,1),imshow(I);title('原影象');
subplot(1,2,2),imshow(J);title('均衡化之後影象');
figure;%顯示原影象和均衡化後圖像的直方圖
subplot(2,3,1),imhist(R,64);ylabel('原影象R通道直方圖');
subplot(2,3,2),imhist(G,64);ylabel('原影象G通道直方圖');
subplot(2,3,3),imhist(B,64);ylabel('原影象B通道直方圖');
subplot(2,3,4),imhist(J(:,:,1),64);ylabel('均衡化之後影象R通道直方圖');
subplot(2,3,5),imhist(J(:,:,2),64);ylabel('均衡化之後影象G通道直方圖');
subplot(2,3,6),imhist(J(:,:,3),64);ylabel('均衡化之後影象B通道直方圖');

灰度影象直方圖均衡化:

%灰度圖直方圖均衡化matlab
clear
I=imread('31.bmp');%讀取灰度影象
J=histeq(I);%直方圖均衡化
figure;%顯示原影象和均衡化後的影象
subplot(1,2,1),imshow(I);title('原影象');
subplot(1,2,2),imshow(J);title('均衡化之後影象');
figure;%顯示原影象和均衡化後圖像的直方圖
subplot(2,1,1),imhist(I,64);title('原影象直方圖');
subplot(2,1,2),imhist(J,64);title('均衡化之後影象直方圖');

彩色影象直方圖均衡化效果圖:



灰度影象直方圖均衡化效果圖: