資源簡介
首先讀入圖像,轉化成hsi彩色空間,然后只對亮度I分量作直方圖均衡化,最后合成三個分量返回到RGB圖,但是這種方法容易使顏色失真,失去了部分圖像細節。
代碼片段和文件信息
clear?
close?all
clc
%讀入彩色圖像,分三個通道顯示,然后在三個通道分別做直方圖的均衡化
h=imread(‘test1.bmp‘);
imshow(h);
title(‘原圖像‘);
h=rgb2hsv(h);%轉到色調,飽和度,亮度空間
fr=h(::1);
fg=h(::2);
fb=h(::3);
figure
subplot(221)imshow(h);
title(‘轉到HSV空間后‘);
subplot(222)imshow(fr);
subplot(223)imshow(fg);
subplot(224)imshow(fb);
figure
subplot(222)imhist(fr);
subplot(223)imhist(fg);
subplot(224)imhist(fb);
title(‘HSV三個分量的直方圖‘);
fb1=histeq(fb);%只對亮度做均衡處理
figureimhist(fb1);
title(‘處理后的亮度直方圖‘);
h1=cat(3frfgfb1);%再次合成后,發現圖像變化
title(‘處理后的HSV圖像‘);
figure
subplot(221)imshow(h1);
subplot(222)imshow(fr);
subplot(223)imshow(fg);
subplot(224)imshow(fb1);
h2=hsv2rgb(h1);
figureimshow(h2);
title(‘再轉回rgb空間‘);
imwrite(h2‘h2.bmp‘);?%?自動寫入圖像,不失真,保證和源圖像大小一樣
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????29516??2010-03-18?08:15??lena.jpg
?????文件????????919??2011-12-02?10:25??sanse2.m
-----------?---------??----------?-----??----
????????????????30435????????????????????2
評論
共有 條評論