 WeightedSumOfLayers Declaration: WeightedSumOfLayers(LayerList: TIntArray; Weights: TDoubleArray; TSlot: integer; var DataMat: TDouble2DArray): integer; Calculates the weighted sum of several layers. The layer indices have to be specified in the open array LayerList, the corresponding weighting factors in the open array Weights. The parameter TSlot determines the time slot which is affected. The resulting matrix is returned in the variable parameter DataMat. It is automatically resized to the required size. The function returns the following error codes:  0 ... everything is OK -1 ... the number of weights does not match the number of layers -2 ... one or more layers are out of range -3 ... TSlot is out of range

 Example: The statement WeightedSumOfLayers([1,10,77],[0.1,0.9,2.11],1,ImgMat); calculates the sum of the layers 1, 10 and 77 of time slot 1, weighting them by the factors 0.1, 0.9 and 2.11, respectively. The result is written into the matrix ImgMat.

 Sample program: The following code lets you select a few layers, then calculates the sum of the selected layers and visualizes the resulting matrix as a special image in the 2D Imager: ```program LayerSum; var imgmat : TDouble2DArray; i : integer; ll : TIntArray; Weights : TDoubleArray; begin SetLength(ll,0); if SelectLayer (1,true,true,ll, 'Please select the layers to be added up') > 0 then begin SetLength(Weights, length(ll)); for i:=1 to length(ll) do Weights[i-1] := 1; WeightedSumOfLayers (ll, Weights, 1, imgmat); AddImgToRepository (imgmat, 1, 1, 'Sum', 'sum of the following layers: '+IntList(ll,'; ')); end; end. ```

Last Update: 2018-Apr-12