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