原理:画面中所期望观察的对象因对比度不足而不够清晰时,通过抑制非重要信息的对比度来腾出空间给重要信息进行对比度的展宽,如下图,原图像的灰度图为f(i,j),处理后的图像为g(i,j)
matlab实现:
clc;
clear;
f = rgb2gray(imread('1.jpg'));%读入图片
figure,imshow(f);%显示图片
%确定对比度展宽的像素范围,
fa = 75;
fb = 150;
ga = 30;
gb = 200;
%求斜率。k>1,表示了重要景物的对比度展宽增强。k<1,表示对非重要景物的抑制
k1 = ga/fa;
k2 = (gb-ga)/(fb-fa);
k3 = (255-gb)/(255-fb);
%求对比度展宽后图像的灰度值
[row,col] = size(f);%将矩阵f的行赋值为row,列赋值为col
g = zeros(row,col);%默认g 为double。g = f;
for i=1:row
for j=1:col
if 0<=f(i,j) && f(i,j)<=fa
g(i,j) = k1*f(i,j);
else if fa<=f(i,j) && f(i,j)<=fb
g(i,j) = k2*(f(i,j)-fa)+ga;
else if fb<=f(i,j) && f(i,j)<=255
g(i,j) = k3*(f(i,j)-fb)+gb;
end
end
end
end
end
figure,imshow(uint8(g));%因为声明g为double,必须转为uint8图像灰度范围[0,255]
|
请发表评论