概况:
灰度变换通过对原图像素值重新分配实现, 目的是使图像中表现较暗的像素值, 通过灰度变换函数映射的方法使较暗的像素值增大, 这样图像的亮度就提高了。增强处理并不能使原始图像信息增加, 其结果只能增强对某种信息的辨别能力, 而这种处理有可能损失一些其他信息。但是, 只要提高了图像的视觉特性, 增强图像的目的就达到了。
几个概念
1、灰度:对于通常所谓的黑白图像,把黑色和白色之间按对数关系分为若干等级称为灰度。灰度分为256阶,用灰度表示的图像称作灰度图.在图像中用0~255表示,0是全黑,255是全白
2、对比度:对比度值一幅图像中敏感区域最亮的白和最暗的黑之间的不同亮度层级的测量,差异范围越大代表对比月大。好的对比率120:1就可以容易的显式生动、丰富的色彩,当对比率达到300:1时便可以支持各阶的颜色。
(1)线性变换:
通过建立灰度映射来调整源图像的灰度。
k>1增强图像的对比度;k=1调节图像亮度,通过改变d值达到调节亮度目的;0
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)对数变换:
增强低灰度,减弱高灰度值。
i = imread('theatre.jpg');
i = rgb2gray(i);
i = double(i);
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时增强高灰度,减弱低灰度。
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) 指数变换:
增强高灰度,减弱低灰度。
i = imread('theatre.jpg');
i = rgb2gray(i);
i = double(i);
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)灰度拉伸:
有时图像灰度集中在某小块区域,需要改变图像对比度。
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);
评论
查看更多