private GaussianBlurArrayComponent[] GenerateForASampleSize(int num) { //In the filter we take advantage of 'free' gpu linear filtering optimiser, to create same effect of a larger sample set. //We need to calculate the weights and offsets of the larger set first var numSamplesOnOneSideIncludingCentre = num + 1; var expandSampleSize = ((numSamplesOnOneSideIncludingCentre - 1) * 2) + 1; var expandedWeightsAndOffsets = CalculateWeightsAndOffsetsOfLargerEquivalentSet(expandSampleSize); var weightsAndOffsets = new GaussianBlurArrayComponent[SAMPLE_ARRAY_SIZE]; weightsAndOffsets[0] = expandedWeightsAndOffsets[0]; for (var n = 1; n < numSamplesOnOneSideIncludingCentre; n++) { var expandedIndex0 = 1 + ((n - 1) * 2); var expandedIndex1 = expandedIndex0 + 1; weightsAndOffsets[n].Weight = expandedWeightsAndOffsets[expandedIndex0].Weight + expandedWeightsAndOffsets[expandedIndex1].Weight; weightsAndOffsets[n].Offset = ((expandedWeightsAndOffsets[expandedIndex0].Weight * expandedWeightsAndOffsets[expandedIndex0].Offset) + (expandedWeightsAndOffsets[expandedIndex1].Weight * expandedWeightsAndOffsets[expandedIndex1].Offset)) / weightsAndOffsets[n].Weight; } return(weightsAndOffsets); }
private GaussianBlurArrayComponent[] CalculateWeightsAndOffsetsOfLargerEquivalentSet(int numSamples) { var tapNumber = (2 * (numSamples - 1)) + 1; var PascalTriangleRowIndexToUse = tapNumber + 3; //We use the row minus the two edge numbers on each side var PascalsTriangleRowSum = (float)Math.Pow(2.0f, PascalTriangleRowIndexToUse); var firstValue = 1; var secondValue = CalculateValueInPascalTriangle(PascalTriangleRowIndexToUse, 1); var adjustedRowSum = PascalsTriangleRowSum - (2 * (firstValue + secondValue)); var halfRow = new float[numSamples]; for (var n = 0; n < numSamples; n++) { var index = n + 2; // we skip the first two values in the pascals triangle halfRow[n] = CalculateValueInPascalTriangle(PascalTriangleRowIndexToUse, index); } var weightsAndOffsets = new GaussianBlurArrayComponent[numSamples]; for (var n = 0; n < numSamples; n++) { weightsAndOffsets[n].Offset = n; var reverse = numSamples - n - 1; weightsAndOffsets[reverse].Weight = (1.0f * halfRow[n]) / (1.0f * adjustedRowSum); } return(weightsAndOffsets); }