A method for detecting materials in a hyperspectral scene, the method comprising: in a detecting engine provided with: i) a spectral library of references in which each reference is a spectrum of a material, ii) dimensional reduced representations of the spectra of a first plurality of pixels included in the hyperspectral scene, the representations including basis vectors associated with the pixels in the hyperspectral scene and dimensional reduced coefficients, and iii) full spectra of a second plurality of other pixels included in the hyperspectral scene, with respect to a subject spectrum of a respective material from the spectral library of references, performing the following steps: for each pixel in the second plurality of pixels, determining a score indicative of the likelihood that the spectrum of a respective pixel matches the subject spectrum of the respective material; transforming the subject spectrum of the respective material into dimensional reduced library coefficients based on the provided basis vectors; for each pixel in the first plurality of pixels, determining which pixel is a variant pixel having dimensional reduced coefficients sufficiently different from dimensional reduced coefficients associated with other pixels; calculating a magnitude of a residual vector associated with the dimensional reduced library coefficients of the respective material; comparing the calculated magnitude of the residual vector to a first threshold; if the result of the comparison is that the calculated magnitude of the residual vector is above the first threshold, determining that the respective material is not present in any of the pixels in the hyperspectral scene represented by the dimensional reduced coefficients; or if the result of the comparison is that the calculated magnitude of the residual vector is below the first threshold, for each variant pixel, determining a score indicative of the likelihood that the dimensional reduced coefficients associated with a respective variant pixel match the dimensional reduced library coefficients of the respective material; comparing the scores to a second threshold; based on the comparison, determining in which of the pixels in the hyperspectral scene the respective material is present. for each pixel in the second plurality of pixels, determining a score indicative of the likelihood that the spectrum of a respective pixel matches the subject spectrum of the respective material; transforming the subject spectrum of the respective material into dimensional reduced library coefficients based on the provided basis vectors; for each pixel in the first plurality of pixels, determining which pixel is a variant pixel having dimensional reduced coefficients sufficiently different from dimensional reduced coefficients associated with other pixels; calculating a magnitude of a residual vector associated with the dimensional reduced library coefficients of the respective material; comparing the calculated magnitude of the residual vector to a first threshold; if the result of the comparison is that the calculated magnitude of the residual vector is above the first threshold, determining that the respective material is not present in any of the pixels in the hyperspectral scene represented by the dimensional reduced coefficients; or if the result of the comparison is that the calculated magnitude of the residual vector is below the first threshold, for each variant pixel, determining a score indicative of the likelihood that the dimensional reduced coefficients associated with a respective variant pixel match the dimensional reduced library coefficients of the respective material; comparing the scores to a second threshold; based on the comparison, determining in which of the pixels in the hyperspectral scene the respective material is present.