數字圖像處理之亮度變換


數字圖像處理之亮度變換

                                           by方陽

版權聲明:本文為博主原創文章,轉載請指明轉載地址

http://www.cnblogs.com/fydeblog/p/6557603.html

第二篇博客,為自己加油加油!!

今天寫一點亮度變換的東西;亮度變換主要有線性與非線性變化和直方圖處理,線性變化有分段線性和直接線性之分,非線性有對數變換,冪律變換等等,直方圖處理有直方圖均衡和直方圖歸一化,今天只講直方圖均衡。

 

今天選的是被廣泛使用的lena圖片,大家有眼福了!直方圖用的是細胞圖,比較明顯!

 

參考書籍:數字圖像處理(matlab版)——岡薩雷斯

 

直接線性變換:直接乘以倍數

參考代碼:

 

I=imread('lena.bmp');
I1=I*2;
I2=I/2;
figure;
subplot(1,3,1);
imshow(I);
title('原圖');
subplot(1,3,2);
imshow(I1);
title('線性2倍');
subplot(1,3,3);
imshow(I2);
title('線性1/2倍');

 運行結果;

 

非線性變換:對數和冪律變換

參考代碼:

figure;
A=double(I);
B=40*(log(A+1));
I3=uint8(B);
subplot(1,3,1);
imshow(I3);
title('對數');
I_D=double(I);
C=I_D/255;
I4=uint8(255*(C.^0.7));
subplot(1,3,2);
imshow(I4);
title('冪律變換—γ=0.5');
I5=uint8(255*(C.^1.3));
subplot(1,3,3);
imshow(I5);
title('冪律變換—γ=1.5');

 運行結果:

分段線性變換:這里只介紹灰度層分級,其他的類似

參考代碼:

figure;
subplot(1,3,1);
imshow(I);
title('原圖');
I6=fy_PiecewiseLinear(I,100,170,1.5);
subplot(1,3,2);
imshow(I6);
title('100到170乘以1.5');
I7=fy_PiecewiseLinear(I,170,220,1/2);
subplot(1,3,3);
imshow(I7);
title('170到220除以1/2');

 灰度級分層函數的實現代碼:

%該函數實現分段線性
%by方陽
function image_out=fy_PiecewiseLinear(image_in ,low_in,high_in,linear_number)
[m,n]=size(image_in);
for i=1:m
    for j=1:n
        if image_in(i,j)>low_in
           if image_in(i,j)<high_in
               image_in(i,j)=image_in(i,j)*linear_number;
           end
        end
    end
end
image_out=image_in;

 運行結果:

最后介紹直方圖均衡

參考代碼:

figure;
I8=imread('fig819.bmp');
h=imhist(I8);
subplot(2,2,1);
imshow(I8);
title('原始圖像');
subplot(2,2,2);
imhist(I8);%imhist是實現顯示當前圖像的直方圖分布
ylim('auto');
title('原始圖像的直方圖');
I9=histeq(I8,256);%histeq是實現直方圖均衡
subplot(2,2,3);
imshow(I9);
title('變換后的圖像');
subplot(2,2,4);
imhist(I9);
title('變換后的直方圖');
ylim('auto');

 運行結果:

就寫到這吧,SEE YOU!!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM