%% ENL和EPI随着sigma_r的变化
clear;
clc;
%% 读取相应的图像和配置参数
f = imread('test.jpg');
if size(f,3) ~=1
f=f(:,:,1);
end
if ~strcmp( class(f),'double' )
f=im2double(f);
end
N = 5; % bilateral filtering half-window
% draw the ENL and EPI variation with sigma_r
ENL=zeros(10,1);
EPI=zeros(10,1);
%设置收敛条件,即精度
epsilon = 0.0001;
%计时开始
tic
%对每个sigma_r进行双边滤波
for i=1:10
sigma_r=0.05+0.05*i;
img1 = bilateral(f,N,2,sigma_r);
ENL(i)=enl(img1);
EPI(i) = epi(f,img1);
end
%归一化
ENL=ENL/max(ENL);
EPI=EPI/max(EPI);
% 指定sigma_r的初始值
start=0.1;
%对归一化后的ENL和EPI进行四次多项式拟合
x=linspace(0.1,0.55,10);
enlc=polyfit(x',ENL,4);
epic=polyfit(x',EPI,4);
%判断起始点位于交点的左边还是右边 1表示左边,0表示右边
direction = 1;
enly1=enlc(1)*start^4+enlc(2)*start^3+enlc(3)*start^2+enlc(4)*start+enlc(5);
epiy1=epic(1)*start^4+epic(2)*start^3+epic(3)*start^2+epic(4)*start+epic(5);
if enly1 > epiy1
direction = 0;
end
%开始进行迭代
constant = 1;
if direction == 1
enlx1=start;
loop_counter=0;
while(constant == 1)
epix2=solve_equation(epic,enly1);
enly3=enlc(1)*epix2^4+enlc(2)*epix2^3+enlc(3)*epix2^2+enlc(4)*epix2+enlc(5);
epix4=solve_equation(epic,enly3);
enly1=enlc(1)*epix4^4+enlc(2)*epix4^3+enlc(3)*epix4^2+enlc(4)*epix4+enlc(5);
loop_counter=loop_counter+1
abs(enlx1-epix4)
if abs(enlx1-epix4) < epsilon
epix4
break;
end
enlx1=epix4;
end
else
epix1=start;
while(constant == 1)
enly2=enlc(1)*epix1^4+enlc(2)*epix1^3+enlc(3)*epix1^2+enlc(4)*epix1+enlc(5);
epix3=solve_equation(epic,enly2);
enly4=enlc(1)*epix3^4+enlc(2)*epix3^3+enlc(3)*epix3^2+enlc(4)*epix3+enlc(5);
epix5=solve_equation(epic,enly4);
abs(epix1-epix5)
if abs(epix1-epix5) < epsilon
epix5
break;
end
epix1=epix5;
end
end
%计时结束
toc