數字圖像處理:圖像的灰度變換(Matlab實現)

(1)線性變換:
經過創建灰度映射來調整源圖像的灰度。函數

k>1加強圖像的對比度;k=1調節圖像亮度,經過改變d值達到調節亮度目的;0ui

i = imread('theatre.jpg');
i = im2double(rgb2gray(i));
[m,n]=size(i);
%增長對比度
Fa = 1.25; Fb = 0;
O = Fa.*i + Fb/255;
figure(1), subplot(221), imshow(O);
title('Fa = 1.25, Fb = 0, contrast increasing');
figure(2),subplot(221), [H,x]=imhist(O, 64);
stem(x, (H/m/n), '.');
title('Fa = 1.25, Fb = 0, contrast increasing');
%減少對比度
Fa =0.5; Fb = 0;
O = Fa.*i + Fb/255;
figure(1), subplot(222),imshow(O);
title('Fa = 0.5, Fb = 0, contrast decreasing');
figure(2), subplot(222), [H,x] = imhist(O, 64);
stem(x, (H/m/n), '.');
title('Fa = 0.5, Fb = 0, contrast decreasing');
%線性亮度增長
Fa = 0.5; Fb = 50;
O = Fa.*i + Fb/255;
figure(1), subplot(223), imshow(O);
title('Fa = 0.5, Fb = 50, brightness control');
figure(2), subplot(223), [H,x]=imhist(O,64);
stem(x, (H/m/n), '.');
title('Fa = 0.5, Fb = 50, brightness control');
%反相顯示
Fa = -1; Fb = 255;
O = Fa.*i + Fb/255;
figure(1), subplot(224), imshow(O);
title('Fa = -1, Fb = 255, reversal processing');
figure(2), subplot(224),[H,x]=imhist(O, 64);
stem(x, (H/m/n), '.');
title('Fa = -1, Fb = 255, reversal processing');

(2)對數變換:
加強低灰度,減弱高灰度值。it

i = imread('theatre.jpg');ast


i = rgb2gray(i);
i = double(i);rsa

out1 = log(1+i)/0.065;
out2 = log(1+i)/0.035;
out1(find(out1>255)) = 255;
out2(find(out2>255)) = 255;
out1 = uint8(out1);
out2 = uint8(out2);

(3)冪次變換:
次數小於1時,加強低灰度,減弱高灰度;次數大於1時加強高灰度,減弱低灰度。im

i = rgb2gray(imread('theatre.jpg'));
i = double(i);
y1 = 255*(i/255).^2.5;
y2 = 255*(i/255).^0.4;
y1 = uint8(y1);
y2 = uint8(y2);

(4) 指數變換:
加強高灰度,減弱低灰度。img

i = imread('theatre.jpg');
i = rgb2gray(i);
i = double(i);process

y1 = 1.5.^(i*0.070)-1;
y2 = 1.5.^(i*0.050)-1;
y1(find(y1>255)) = 255;
y2(find(y2>255)) = 255;
y1 = uint8(y1);
y2 = uint8(y2);

(5)灰度拉伸:
有時圖像灰度集中在某小塊區域,須要改變圖像對比度。co

i = imread('theatre.jpg');
i = rgb2gray(i);
L = imadjust(i,[ ],[50/255;150/255]);
J = imadjust(L,[50/255;150/255 ],[20/255;230/255]);

(6)灰度均衡:
i = rgb2gray(imread('theatre.jpg'));
LC = imadjust(i,[ ],[50/255;150/255]);
HE1 = histeq(LC);%均衡函數

(7)直方圖規定化:
實現局部的灰度均衡。

img = rgb2gray(imread('theatre.jpg'));img_ref = rgb2gray(imread('rpic.jpg'));%參考圖,按照這個的的直方圖進行規定化[hgram, x] = imhist(img_ref);J = histeq(img, hgram);

相關文章
相關標籤/搜索