将图片变清晰的过程就叫做图像增强
首先介绍一些基本的灰度变换函数:
- 图像反转
图像反转公式如下:s=L-1-r,其中L为256,r为原像素值,s为反转后的像素值
图像反转适合用于增强暗区域中的白色或灰色细节
clear;clc
I=rgb2gray(imread('pic.jpg'));
L=256;
out=L-1-I;
subplot(1,2,1);imshow(I);title('原图');
subplot(1,2,2);imshow(out);title('反转后的图');
实验结果图:
- 对数变化
对数变化的通用形式为:s=c*log(1+r);其中c为常数,r为原像素值,s为变换后的像素值
clear;clc
I=rgb2gray(imread('pic.jpg'));
I = double(I);
c1=.1;
c2=.05;
out1=c1*log(1+I);
out2=c2*log(1+I);
subplot(1,3,1);imshow(uint8(I));title('原图');
subplot(1,3,2);imshow((out1));title('c=0.1');
subplot(1,3,3);imshow((out2));title('c=0.05');
实验结果如下:
- 幂律变换
s=c*r.^(a) c乘以r的a次方的意思,r为原像素值,s为变化的像素值
a>1,降低灰度级,让图像变暗
a<1,提高灰度级,让图像变亮
I=rgb2gray(imread('pic.jpg'));
I = double(I);
c1=0.01;
c2=0.01;
r1=0.7;
r2=1.1;
out1=c1*I.^r1;
out2=c2*I.^r2;
subplot(1,3,1);imshow(uint8(I));title('原图');
subplot(1,3,2);imshow((out1));title('c1=0.01 r1=0.7')
subplot(1,3,3);imshow((out2));title('c2=0.01 r2=1.1');