image thumbnail

Software for hyper-spectral data pre-processing

by

 

07 Mar 2013 (Updated )

The software offers a user-friendly tool (based on two GUIs) for pre-processing reflectance spectra

[L_onda,S_norm]=convex_hull_spectra(choise_asdtype,FileName,FilePath,corr_atm,spettro_norm,rimoz_badcal,lam,lam_in,lam_fin,inRemove_noiseCsx,edit10,edit11,handles_axes)
function [L_onda,S_norm]=convex_hull_spectra(choise_asdtype,FileName,FilePath,corr_atm,spettro_norm,rimoz_badcal,lam,lam_in,lam_fin,inRemove_noiseCsx,edit10,edit11,handles_axes)

if isempty(lam),
    lam=350;
end
if isempty(lam_in),
    lam_in=350;
end
if isempty(lam_fin),
    lam_fin=2350;
end

c_ang = 0;
setappdata(0,'UseNativeSystemDialogs',0) 
dati=read_multiple_asdfiles(FileName,FilePath,choise_asdtype);

[righe colonne] = size(dati);
dati = dati';
ss = size(dati);
nr_spettri = ss(1);

% *************************************
% Atmospheric band removal
%**************************************
edit11=edit11-350;
if strcmp(corr_atm,'YES') || isempty(corr_atm),
    for i=1:length(edit11)/2,
    for kk=1:nr_spettri,
            yy1 = dati(kk,edit11(2*i-1));
            yy2 = dati(kk,edit11(2*i));
            delta_yy = (yy2-yy1)/(edit11(2*i)-edit11(2*i-1));

            for y=1:edit11(2*i)-edit11(2*i-1),
                dati(kk,y+edit11(2*i-1)) = dati(kk,edit11(2*i-1))+(delta_yy*y);
            end
            
    end
    end
end


% *************************************
% Remove sensor bad calibration
% *************************************
edit10=edit10-350;
if strcmp(rimoz_badcal,'YES') || isempty(rimoz_badcal),
dati2 = dati;
for kk=1:colonne,
       delta1 = dati(kk,edit10(1))-dati(kk,edit10(1)-1);
       delta2 = dati(kk,edit10(2))-dati(kk,edit10(2)+1);
       dd = (delta2 - delta1)/(edit10(2)-edit10(1)+1);
       for y=0:edit10(2)-edit10(1),
           dati2(kk,y+edit10(1)) = dati(kk,y+edit10(1))-(delta1)-(dd*y);
       end
end
dati = dati2;
end

x = dati(:,:);

if inRemove_noiseCsx ~= 0,
    x(:,1:inRemove_noiseCsx) = 0;
end
x(:,2151) = 0;  
lambda = (350:2500); 
if strcmp(spettro_norm,'NO'),
normalizzato = x(:,1:2151);
elseif strcmp(spettro_norm,'YES') || isempty(spettro_norm),
normalizzato = zeros(nr_spettri,2151);
for s = 1:nr_spettri,
    rifl = x(s,:);
    k = convhull(lambda,rifl);
    c = [rifl(k); lambda(k)];
    d = sortrows(c',2);
    rifl_i = zeros(2151,1);

    conta = 1;
    %convex hull spectrum calculus
    for xx=1:(size(k)-2), 
        x1 = d(xx,1); %rifl1
        y1 = d(xx,2); %lambda1
        x2 = d(xx+1,1); %rifl2
        y2 = d(xx+1,2); %lamdba2
        if ((y2 -y1) > 0)
            c_ang = (x2-x1)/(y2-y1);
        end
   
        conta = conta-1;
        conta2 = 0;
        for yy=y1:y2,
            conta = conta+1;
            conta2 = conta2+1;
            rifl_i(conta) = (conta2*c_ang) + x1;
        end
    end
% Signature Normalization (relative to the convex hull spectrum)
    for t = 1:2151, 
        if rifl_i(t) ~= 0
            normalizzato(s,t) = rifl(t)/rifl_i(t);
        else
            normalizzato(s,t) = 1;
        end
    end
end
end

lam_in=double(lam_in);
lam_fin=double(lam_fin);
lambda = lam_in:lam_fin;

normalizzatobis=normalizzato(:,lam_in-350+1:lam_fin-350+1);
sl_fin = [lambda' normalizzatobis'];
sldp = [350:2500; normalizzato];
outt = sldp(2:end,double(lam)-350+1);
L_onda=lambda';S_norm=normalizzatobis';
size_snorm=size(S_norm);
axes(handles_axes(1))
plot(L_onda,S_norm)
xlabel('Wavelength [nm]')
ylabel(['Reflectance  -','  number of samples = ',num2str(size_snorm(2))])
axis([L_onda(1) L_onda(end) 0 1.1])
grid on
axes(handles_axes(2))
plot(1:length(outt),sort(1-outt),'r','LineWidth',2)
ylabel(['Signature depth for selected wavelength = ',num2str(lam),'nm'])
xlabel('Number of the signals (sort in ascending order) with Depth relative to reflectance = 1')
grid on

options_idlg.Resize='on';
options_idlg.WindowStyle='normal';
name_library=char(inputdlg('Enter file name','Save spectral library',1,{''},options_idlg));
if ~isempty(name_library),
dlmwrite([name_library,'.txt'],sl_fin,'delimiter','\t');
end
name_DepthPeak=char(inputdlg('Enter file name','Save depth peaks',1,{''},options_idlg));
if ~isempty(name_DepthPeak),
dlmwrite([name_DepthPeak,'.txt'],sort(1-outt),'delimiter','\t');
end

Contact us