多光谱数据处理

clear;clc;close all;
str='L:\pianzheng\20170914\Image_'; 
for i=65:110
  %  I{i} = imread([str,num2str(i),'.tif']); %依次读取每一幅图像
    I{i} = double(imread([str,num2str(i),'.tif'])); %依次读取每一幅图像
end

position = zeros(16,2);
position(1,1:2) = [887,718];
position(2,1:2) = [1175,718];
position(3,1:2) = [1419,702];
position(4,1:2) = [711,914];
position(5,1:2) = [915,910];
position(6,1:2) = [1107,906];
position(7,1:2) = [1279,906];
position(8,1:2) = [1435,902];

position(9,1:2) = [1095,1118];
position(10,1:2) = [1283,1122];
position(11,1:2) = [1475,1110];
position(12,1:2) = [915,1298];
position(13,1:2) = [1095,1298];
position(14,1:2) = [1267,1294];
position(15,1:2) = [1475,1274];
position(16,1:2) = [1211,1038];


x = 650:10:1100;
point = zeros(1,46);

%测试窗函数
pic = I{65};
figure,imagesc(pic),colormap gray,axis tight equal;
for k = 1:16 
    pic(position(k,2):position(k,2)+29,position(k,1):position(k,1)+29) = max(pic(:));
end
figure,imagesc(pic),colormap gray,axis tight equal;

figure;
for k = 1:16
    for i = 65:110
        pic = I{i};
        point(i-64) = mean(mean(pic(position(k,2):position(k,2)+29 , position(k,1):position(k,1)+29)));
%        point(i-64) = pic(position(k,2),position(k,1));
    end
    subplot(4,4,k);
    plot(x,point);
    hold on;
end

figure;
%str = {'材料1','材料2','材料3','材料4','材料5','材料6','材料7','材料8','材料9','材料10','材料11','材料12','材料13','材料14','材料15'};
str = {'材料1','材料2','材料3','材料4','材料5','材料6','材料7','材料8','材料9','聚酰亚胺渗碳膜(防杂光)','双面镀铝薄膜','低反射率涂层绸','聚酰亚胺镀铝膜','防原子氧布(低轨卫星用)','氟46膜(低吸收高反射)'};
type = {'b-','g-','r-','m-','k-','b:','g:','r:','m:','k:','b-.','g-.','r-.','m-.','k-.'};
for k = 1:15
    for i = 65:110
        pic = I{i};
        point(i-64) = mean(mean(pic(position(k,2):position(k,2)+29 , position(k,1):position(k,1)+29)));
%        point(i-64) = pic(position(k,2),position(k,1));
    end
%    subplot(4,4,k);

%%%%%%g归一化处理,归一到10000%%%
    max_number = max(point);
    point = point/max_number;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
    plot(x,point,type{k});
    hold on;
end
legend(str);
%suptitle('光谱图');
title('不同材料归一化光谱图','fontsize',12,'fontweight','b','color','k');
xlabel('波长/nm','fontsize',12,'fontweight','b','color','k');
ylabel('灰度归一化','fontsize',12,'fontweight','b','color','k');


figure;
str = {'普通布料','双面镀铝薄膜','防原子氧布(低轨卫星用)','氟46膜(低吸收高反射)'};
for k = 1:4
    
    switch k
        case 1
            t = 2;
        case 2 
            t = 11;
        case 3
            t = 14;
        case 4
            t = 15;
    end  
    for i = 65:110
        pic = I{i};
        point(i-64) = mean(mean(pic(position(t,2):position(t,2)+29 , position(t,1):position(t,1)+29)));
%        point(i-64) = pic(position(k,2),position(k,1));
    end
    if k == 1
        suptitle('光谱图');
    end
    subplot(2,2,k);
    plot(x,point,'r.-');
    xlabel('波长/nm','fontsize',8,'fontweight','b','color','k');
    ylabel('灰度值','fontsize',8,'fontweight','b','color','k');
    legend(str{k});
end


figure;
%str = {'材料1','材料2','材料3','材料4','材料5','材料6','材料7','材料8','材料9','材料10','材料11','材料12','材料13','材料14','材料15'};
str = {'材料1','材料2','材料3','材料4','材料5','材料6','材料7','材料8','材料9','聚酰亚胺渗碳膜(防杂光)','双面镀铝薄膜','低反射率涂层绸','聚酰亚胺镀铝膜','防原子氧布(低轨卫星用)','氟46膜(低吸收高反射)'};
type = {'b-','g-','r-','m-','k-','b:','g:','r:','m:','k:','b-.','g-.','r-.','m-.','k-.'};
for k = 1:15
    for i = 65:110
        pic = I{i};
        point(i-64) = mean(mean(pic(position(k,2):position(k,2)+29 , position(k,1):position(k,1)+29))) / mean(mean(pic(position(16,2):position(16,2)+29 , position(16,1):position(16,1)+29)));
%        point(i-64) = pic(position(k,2),position(k,1));
    end
    if k == 1
        suptitle('光谱图(与背景的比值)');
    end
    subplot(4,4,k);
    plot(x,point,type{3});
    legend(str{k});
    xlabel('波长/nm','fontweight','b','fontsize',8,'color','k');
    ylabel('灰度与背景的比值','fontweight','b','fontsize',8,'color','k');
end
%suptitle('光谱图');

作为matlab参考代码,帮助编程。

你可能感兴趣的:(代码)