DetectSpikes

Declaration: DetectSpikes (HalfWidth, FirstLayer, LastLayer, TimeSlot: integer; UseLinFit: boolean; RecogLevel: double; var SpikeMat: TDouble3DArray; var SpikeList: TIntArray; FeedBack: boolean): integer;
Detects spikes in all pixels of the hyperspectral image; for a short discussion of the detection algorithm see the section on the Spike Removal Tool. The spectral range can be restricted by setting the parameters FirstLayer and LastLayer. Please note that in the case of data cubes containing more than one spectral group, you have to set these parameters such that they are specifying layers which belong to the same spectral group (use the function ObtainSpecRange to retrieve the range of a spectral group). The parameter TimeSlot controls the time slot to be processed.

The parameter HalfWidth specifies the expected width of a spike. This parameter is quite sensitive for the quality of spike recognition, normally it should be set to 1 (unless the spikes are broader than one data point).

There are two baseline approximation methods available, which are selected by setting the parameter UseLinFit. If UseLinFit is TRUE a linear fit is used, otherwise a parabolic fit is applied to model the baseline. The parameter RecogLevel defines the sensitivity of spike recognition (i.e. the required minimum ratio of the deviation of data point from the baseline to the baseline noise).

The function returns the information on the detected spikes in two arrays: (1) The three-dimensional array SpikeMat contains the spike scores (= the ratio of the deviation of data point from the baseline to the baseline noise) of a maximum of three spikes for each pixel. If a spectrum contains less than three spikes the unused cells in SpikeMat are zero, if a spectrum contains more than three spikes, the forth and all other spikes are listed in SpikeList, but the scores are not stored in SpikeMat. (2) The one-dimensional integer array SpikeList contains the addresses of the spikes in encoded form: the value in each cell of the array is calculated according to the following equation:
   value = ((ix-1)+(iy-1)*SizeX)*SizeL+il-1,
with ix, iy, and il being the x, y, and layer index of the data cube, SizeX the number of pixels along the x-axis and SizeL the number of layers of the data cube.

If FeedBack is TRUE the progress of the routine is displayed using the script progress bar. Please note that unless the script progress bar is already visible you have to make it visible before calling DetectSpikes, otherwise the feedback will not be displayed. You can activate the script progress bar by calling the function ScriptBar(0).

The function returns the following error codes:

 0 ... everything is OK
-1 ... the HalfWidth is out of range (valid range: 1..100)
-2 ... the LastLayer is less than or equal to the FirstLayer
-3 ... the FirstLayer or the LastLayer are out of range
-4 ... invalid TimeSlot
-5 ... the recognition level in out of range (valid range: >= 2.0)

Hint 1: In order to actually remove the detected spikes you have to call the function RemoveSpikes after detecting them

Hint 2: The spike detection and removal must not be applied to line spectra which do not exhibit any correlation between neighboring intensities (e.g. mass spectra).