clear all;
clc;
% Crepl=load('dd');
I=imread('object.bmp');
I=double(I);
sz=256;
nfrm=100;
% size(Crepl)
obs=scan(I,sz,nfrm);
[sy,sx,N]=size(obs);
g=-(randn(size(obs(:,:,1)))*0.02+1);
b=randn(size(obs(:,:,1)))*0.5*std(obs(:));
%分配内存
med1=zeros(size(obs));med2=zeros(size(obs));
med3=zeros(size(obs));med4=zeros(size(obs));
out1=zeros(size(obs));out2=zeros(size(obs));
out3=zeros(size(obs));outstd1=zeros(size(obs));
outstd2=zeros(size(obs));outstd3=zeros(size(obs));
C=obs;
nobs=zeros(size(obs));
corrfrm=zeros(size(obs));
detn=detectornu(obs,g,b); %添加探测器噪声
nobs=addchannoise(detn); %添加读出噪声
%指标提取信号处理通道输出
in1=1:1:sy;in2=1:4:sx;
in3=2:4:sx;in4=3:4:sx;in5=4:4:sx;
%alpha修正因子
alpha=3;
%采用通道非均匀校正
corrfrm=framechanncorr(nobs,in1,in2,in3,in4,in5,alpha);
% corrfrm=log(256./corrfrm-1);
%2M1+1是中值滤波器的长度
%三种不同的中值滤波器
M1=2; M2=4; M3=6;
% 进行中值滤波
for i=1:N
result=corrfrm( :, :,i);
fk=uint8(result);
disp(sprintf('filtering frame %d',i));
%中值滤波用于信道非均匀校正
med1(:,:,i)=med2d(padarray(fk,[M1,M1],'replicate'),2*M1+1,2*M1+1);
med2(:,:,i)=med2d(padarray(fk,[M2,M2],'symmetric'),2*M2+1,2*M2+1);
med3(:,:,i)=med2d(padarray(fk,[M3,M3],'circular'),2*M3+1,2*M3+1);
%中值滤波用于没有经过非均匀校正后的帧频图像
med4(:,:,i)=med2d(padarray(nobs(:,:,i),[M1,M1]),2*M1+1,2*M1+1);
% med4(:,:,i)=med2d(nobs(:,:,i),2*M1+1,2*M1+1);
end
figure;
%经过信道非均匀校正后基于RLS方法对探测器的非均匀校正
%均值滤波器的大小是5×5
[Grls1,Brls1,out1,outstd1,errrls1,errstd1,snrrls1,snrstd1] =recurlsstda(...
corrfrm,nobs,med1,obs,max(nobs(:)),1,M1);
figure;
%没有经过信道非均匀校正的基于RLS法对探测器的非均匀校正
%均值滤波器的大小是5×5
[Grls11,Brls11,out11,outstd11,errrls11,errstd11,snrrls11,...
snrstdll]=recurlsstda(nobs,nobs,med4,obs,max(nobs(:)),1,M1);
figure;
%经过信道非均匀校正后基于RLS方法对探测器的非均匀校正
%均值滤波器的大小是9×9
[Grls2,Brls2,out2,outstd2,errrls2,errstd2,snrrls2,snrstd2]=recurlsstda(...
corrfrm,nobs,med2,obs,max(nobs(:)),1,M2);
figure;
%经过信道非均匀校正后基于RLS方法对探测器的非均匀校正
%均值滤波器的大小是13×13
[Grls3,Brls3,out3,outstd3,errrls3,errstd3,snrrls3,snrstd3]=recurlsstda(...
corrfrm,nobs,med3,obs,max(nobs(:)),1,M3);
figure;
%画出误差图(MAE)
st=3;frame=st:1:N;
h1=figure;
plot(frame,errrls1(st:N) ,'r-.',frame,errrls2(st:N),'b-*',frame,errrls3(st:N),'c-o');
set(get(h1,'CurrentAxes'),'FontSize',10);
title('error Vs frame');
xlabel('Number of frames','FontSize',18);
ylabel('Mean Absolute Error','FontSize',18);
legend('5x5 Median Filter','9x9 Median Filter','13x13 Median',1);
%输出误差
%画出SNR
h34=figure;
plot(frame,snrrls1(st:N),'r-.',frame,snrrls2(st:N),'b-*',frame,snrrls3(st:N),'c-o');
set(get(h34,'CurrentAxes'),'FontSize',10);
title('SNR Vs frame');
xlabel('Number of Frames','FontSize',18);
ylabel('Signal to Noise Ratio','FontSize',18);
legend('5x5 Median Filter','9x9 Median Filter','13x13 Median Filter',2);
%输出 snr.ps
%显示图像
h3=figure;imstd(I);
set(get(h3,'CurrentAxes'),'FontSize',20);
%输出tvi.ps
h4=figure;imstd(obs(:,:,N));
set(get(h4,'CurrentAxes'),'FontSize',20);
%输出raw.ps
h5=figure;imstd(detn(:,:,N));
set(get(h5,'CurrentAxes'),'FontSize',20);
%输出 detn.ps
h6=figure;imstd(nobs(:,:,N));
set(get(h6,'CurrentAxes'),'FontSize',20);
title('after channel noise');
%输出 noisyfrm.ps
h7=figure;imstd(corrfrm(:,:,N));
set(get(h7,'CurrentAxes'),'FontSize',20);
title('after channel correction');
%输出chanco.ps
h8=figure;imstd(med1(:,:,N));
set(get(h8,'CurrentAxes'),'FontSize',20);
title('Median Filtered (Preliminary Scene Estimate) after readout correction');
%输出 med5.ps
h9=figure;imstd(outstd1(:,:,N));
set(get(h9,'CurrentAxes'),'FontSize',20);
title('Corrected Frame Using STD Parameters (100 Frames) after channel correction');
%输出 rls5.ps
h10=figure;imstd(out1(:,:,N));
set(get(h10,'CurrentAxes'),'FontSize',20);
title('Corrected Frame Using RLS Parameters (100 Frames) after channel correction');