Declaration: CreateBackgroundMask(FirstLayer, LastLayer, TimeSlot: integer; Percentile: double; var PixMask: TInt2DArray; FeedBack: boolean): integer;
Calculates two pixel masks indicating those pixels which do not contain any important spectral information ("background pixels"). See here for an explanation of the algorithm.

The parameters FirstLayer and LastLayer specify the range of layers to be used for the calculation. The parameter TimeSlot specifies the time slot to be used. The parameter Percentile determines the threshold for determining non-background pixels. Its valid range is between 0.0 and 50.0, useful values are normally between 2 and 15. The higher this value the less pixels will be recognized as background pixels. The found background pixels are stored in the array PixMask, which is automatically resized to the size of the data cube. Bit 0 of each cell corresponds to an intensity deviation towards minus infinity, bit 1 indicates the deviation toward plus infinity.

The Feedback determines whether a visual feedback is provided. Please note that unless the script progress bar is already visible you have to make it visible before calling CreateBackgroundMask, 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 numbers:

 0 ... everything is OK
-1 ... FirstLayer and/or LastLayer is out of range
-2 ... TimeSlot is out of range
-3 ... Percentile is out of range
-4 ... calculation aborted by user by pressing <ESC>