Code covered by the BSD License  

Highlights from
Spectral Match

Spectral Match

by

 

Can be used in HyperSpectral Image Remote Sensing. Produces a matching/Score matrix.

[Output]=SpectraMatch(Data,SpectralDB,Method)
%%
% Copyright (c) 2013, Mohammad Abouali (maboualiedu@gmail.com)
% All rights reserved.
% 
% Redistribution and use in source and binary forms, with or without 
% modification, are permitted provided that the following conditions are 
% met:
% 
%     * Redistributions of source code must retain the above copyright 
%       notice, this list of conditions and the following disclaimer.
%     * Redistributions in binary form must reproduce the above copyright 
%       notice, this list of conditions and the following disclaimer in 
%       the documentation and/or other materials provided with the distribution
%       
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
% POSSIBILITY OF SUCH DAMAGE.

%%
function [Output]=SpectraMatch(Data,SpectralDB,Method)
%% Spectral Match based on the provided Spectral data base generates an output
%  showing how good each entry of your data matches to each entry of the
%  spectral database.
%
%  INPUTS:
%     -- Data: must be of size nBand x nPixel, that is each columns is one
%              measurements or pixel of your hyperspectral images.
%     -- SpectralDB: must be of size nBand x nSpectra, where nSpectra
%                    varies based on howmany entries you have in your
%                    database.
%     -- Method: Computes the match. Currently there are two methods:
%                (1) RMSE: The lower the better match.
%                (2) DotProduct: the closer to 1 the better.
%
%  OUTPUTS
%     -- Output: would be of size nPixel x nSpectra. Each entry, i.e. (i,j) element,
%                shows the matching criteria, i.e. RMSE or DotProduct, 
%                of the pixel i with the database spectra j

% Getting some size information
[nBand, nSpectra ]=size(SpectralDB);
disp(['Number of Spectra: ' num2str(nSpectra)]);
disp(['Number of Bands: ' num2str(nBand)]);

nPixel=size(Data,2);
disp(['Number of pixels: ' num2str(nPixel)]);
if (nBand~=size(Data,1))
  error('Spectral database and the image must have the same number of bands')
end

% Initializing and reserving memory
Output=zeros(nPixel,nSpectra);

switch lower(Method)
  case 'rmse'
    % Actually calculating the RMSE
    for i=1:nSpectra
      SingleSP=repmat(SpectralDB(:,i),1,nPixel);
      Output(:,i)=transpose(sqrt(mean((Data-SingleSP).^2)));
    end

  case 'dotproduct'
    normData=sum(Data.^2).^0.5;
    for i=1:nSpectra
      SingleSP=repmat(SpectralDB(:,i),1,nPixel);
      normSingleSP=sum(SingleSP.^2).^0.5;
      Output(:,i)=transpose( sum(Data.*SingleSP)./(normSingleSP.*normData) );
    end

  otherwise
    disp('Acceptable values for methods are:')
    disp('-- RMSE')
    disp('-- DotProduct')
    error('Method is not found');
end

end

Contact us