clear;
clc;
%%%%%%%%%%%%%%低温下对9帧图像取平均值%%%%%%%%%%%%%
save1=zeros(3,2,9,'uint16');
for i = 1:9; %连续读M帧图像,存入三维数组
fid = textread(strcat('300',num2str(i),'b.txt'),'%s');
fid1 = hex2dec(fid);
save1(:,:,i) = reshape(fid1,3,2);
end
%求M帧的平均值,消除偶然误差
sample1 = zeros(3,2,'double');
sample1 = double(save1(:,:,1)+save1(:,:,2)+save1(:,:,3)+save1(:,:,4)+save1(:,:,5)+save1(:,:,6)+save1(:,:,7)+save1(:,:,8)+save1(:,:,9))/9;
subplot(2,2,1), imshow(uint8(sample1));
title('T1温度原始图');
%%%%%%%%%%%%%低温下对9帧图像取平均值%%%%%%%%%%%%%%%
save2=zeros(3,2,9,'uint16');
for i = 1:9;
fid = textread(strcat('700',num2str(i),'b.txt'),'%s');
fid1 = hex2dec(fid);
save2(:,:,i) = reshape(fid1,3,2);
end
sample2 = zeros(3,2,'double');
sample2= double(save2(:,:,1)+save2(:,:,2)+save2(:,:,3)+save2(:,:,4)+save2(:,:,5)+save2(:,:,6)+save2(:,:,7)+save2(:,:,8)+save2(:,:,9))/9;
subplot(2,2,2),imshow(uint8(sample2));
title('T2温度原始图');
%%%%%%%%%%%%%%%计算校正因子%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
avr1=sum(sample1(:))/(3*2);
avr2=sum(sample2(:))/(3*2);
G = zeros(3,2,'double');
O = zeros(3,2,'double');
M = zeros(3,2,'double');
for i=1:3;
for j=1:2;
G(i,j) = (avr2-avr1)/(sample2(i,j)-sample1(i,j)); %计算增益
O(i,j) = avr1-G(i,j)*sample1(i,j); %计算偏移量
%O(i,j) =(avr2*double(sample1(i,j))-avr1*double(sample2(i,j)))/double(sample1(i,j)-sample2(i,j));
end
end
file = fopen('2dian4p000s17.txt','wt');
count = fwrite(file,G,'uint16');
%%%%%%%%%%%%%%校正场景图片%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid = textread('4p000s.txt','%s');
fid1 = hex2dec(fid);
test2=reshape(fid1,3,2);
%%%%%%%%%%%%%%%%%%%%%%%%%校正得到全部结果%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:3;
for j=1:2;
M(i,j) = G(i,j)*double(test2(i,j))+O(i,j);
end
end
for i=1:3;
for j=1:2;
final(i,j) = uint16(M(i,j));
end
end
subplot(2,2,3),imshow(uint8(final));title('校正后 ');
subplot(2,2,4),imshow(uint8(test2));title('非均匀原始图');
file = fopen('2dian4p000s16.txt','wt');
count = fwrite(file,final,'double');
评论4