Cast-Aways
Make your constants double at compile time.
BubbleFrame[b, a, c] = 0D;, 0.12D, BubbleFrame[b + 1, a - 1, c - 1] = 0D etc. Well, 0.12 is already a double, but what the heck.
BubbleCounter is used as a value in the matrix. Declare it as double and pass it as a double.
Guessing At Performance
Not this:
calibline= BubbleReader.ReadLine();
numbers = calibline.Split(' ');
for (int a = 0; a < Sensor; a++)
{
BubbleFrame[b, a, c] = Convert.ToDouble(numbers[a]);
}
but this:
BubbleFrame[b,a] = Array.ConvertAll(BubbleReader.ReadLine().Split(' '), double.Parse);
I honestly don't know that if this is more performant. And I hope the new array does not have > Sensor values!
Why this?
Maxvalue = BubbleFrame.Cast<double>().Max();
Aren't BubbleFrame values already double?
Calculate once; and avoid unnecessary call:
Cminus1 = c-1;
if (Cminus1 > 0)
BubbleSearchCMinus1(ref BubbleFrame, ref BubbleCollection, ref Cminus1, ref b, ref a, ref Threshold, ref BubbleCounter, ref Sensor, ref n_fr);
then inside:
BubbleSearchCMinus1(ref double[, ,] BubbleFrame,ref double[, ,] BubbleCollection, ref int c, ref int b, ref int a, ref double Threshold, ref int BubbleCounter, ref int Sensor, ref int n_fr) {
Bminus1 = b-1; Bplus1 = b+1;
}