Gamma变换
与前述log变换相似,Gamma变换属于非线性操作,非线性变换的主要目的是通过灰度值映射增强目标域数据分布,达到对比度增强的目的。Gamma变换可以根据参数变换的更加灵活,其灰度变换函数定义如下:
s
=
c
r
γ
s=cr^{\gamma}
s=crγ其中gamma函数的变换图像如下:
同样是与log变换类似,gamma变换通过非线性变换完成不同域值之间的映射,达到图像增强的目的:
对应取反时的效果:
代码
gamma变换
x = 0:0.01:1;
c =2;
y1 = PowerLaw_f(1,0.04,x);
y2 = PowerLaw_f(1,0.10,x);
y3 = PowerLaw_f(1,0.20,x);
y4 = PowerLaw_f(1,0.40,x);
y5 = PowerLaw_f(1,0.80,x);
y6 = PowerLaw_f(1,1.2,x);
y7 = PowerLaw_f(1,2.5,x);
y8= PowerLaw_f(1,5.0,x);
y9 = PowerLaw_f(1,10.0,x);
y10 = PowerLaw_f(1,25.0,x);
y11 = PowerLaw_f(1,1,x);
plot(x,y1,'g',x,y2,'r',x,y3,'b',x,y4,'c',x,y5,'y',x,y10,'g',x,y9,'r',x,y8,'b',x,y7,'c',x,y6,'y',x,y11,'b');
xlabel('Input gray level');
ylabel('Output gray level');
title('Gamma Transform')
text(0.1,PowerLaw_f(1,0.04,0.1),"0.04");
text(0.2,PowerLaw_f(1,0.10,0.2),"0.10");
text(0.3,PowerLaw_f(1,0.20,0.3),"0.20");
text(0.4,PowerLaw_f(1,0.40,0.4),"0.40");
text(0.5,PowerLaw_f(1,0.80,0.5),"0.80");
text(0.7,PowerLaw_f(1,1.20,0.7),"1.20");
text(0.8,PowerLaw_f(1,2.50,0.8),"2.50");
text(0.9,PowerLaw_f(1,10.0,0.9),"10.0");
text(1.0,PowerLaw_f(1,25.0,1.0),"25.0");
text(0.6,PowerLaw_f(1,1,0.6),"1");
图像增强
%% PowerLaw_f.m
function [res] = PowerLaw_f(c,gamma,img)
res = (c.*img).^gamma;
end
%% PowerLaw_base.m
close all;
clc
clear
img = double(dicomread('D:\dataset\AMRGAtlas\UOA0000101\IM-0004-0012.dcm'));
img_gray = mat2gray(img);
img_1 = img_gray(: ,: ,1);
figure(1);
gamma1 =15.0;
gamma2 = 0.3;
res1 = PowerLaw_f(1,gamma1,img_gray);
res2 = PowerLaw_f(1,gamma2,img_gray);
subplot(3,3,1);
imshow(img_gray,[0 1]);
xlabel('gray');
subplot(3,3,4);
imshow(res1,[0 1]);
xlabel(['\gamma= ',num2str(gamma1)]);
subplot(3,3,7);
imshow(res2,[0 1]);
xlabel(['\gamma= ',num2str(gamma2)]);
a=256;
subplot(3,3,2);
imhist(img_gray,a)
title('灰度图hist');
subplot(3,3,5);
imhist(res1,a)
title(['\gamma= ',num2str(gamma1)]);
subplot(3,3,8);
imhist(res2,a)
title(['\gamma= ',num2str(gamma2)]);
x =0:0.01:1;
subplot(333);
y1 = PowerLaw_f(1,1,x);
plot(x,y1);
title(['\gamma= ',num2str(1)]);
subplot(336);
y2 = PowerLaw_f(1,gamma1,x);
plot(x,y2);
title(['\gamma= ',num2str(gamma1)]);
subplot(339);
y3 = PowerLaw_f(1,gamma2,x);
plot(x,y3);
title(['\gamma= ',num2str(gamma2)]);