SHOW:
|
|
- or go back to the newest paste.
| 1 | - | static void Main(string[] args) |
| 1 | + | // Calculation of image statistics |
| 2 | - | {
|
| 2 | + | // We could use LINQ to get Min and Max easily but this way we do it all |
| 3 | - | int[,] arr = new int[,] { { 1, 2, 3 }, { 3, 4, 4 }, { 5, 6, 2 }, { 7, 8, 2 } };
|
| 3 | + | // in a single passege through image matrix |
| 4 | Stopwatch stopWatch = new Stopwatch(); | |
| 5 | - | for (int x = 0; x < arr.GetLength(0); x++) |
| 5 | + | stopWatch.Start(); |
| 6 | UInt16 tempMin = (UInt16)(Math.Pow(2, mfvm.cameras[openCamIndex].bitDepth) - 1); | |
| 7 | - | StringBuilder sb = new StringBuilder(); |
| 7 | + | UInt16 tempMax = acquisition.frameDataShorts.AsParallel().Max(); |
| 8 | UInt64 tempSum = 0; | |
| 9 | - | for (int y = 0; y < arr.GetLength(1); y++) |
| 9 | + | |
| 10 | - | {
|
| 10 | + | stopWatch.Stop(); |
| 11 | - | sb.Append(String.Format("\t{0}", arr[x, y]));
|
| 11 | + | for (int i = 0; i < acquisition.frameDataShorts.Length; i++) |
| 12 | - | } |
| 12 | + | |
| 13 | - | Console.WriteLine("{0}", sb.ToString());
|
| 13 | + | if (acquisition.frameDataShorts[i] < tempMin) |
| 14 | tempMin = acquisition.frameDataShorts[i]; | |
| 15 | ||
| 16 | - | int max = int.MinValue; |
| 16 | + | if (acquisition.frameDataShorts[i] > tempMax) |
| 17 | - | int min = int.MaxValue; |
| 17 | + | tempMax = acquisition.frameDataShorts[i]; |
| 18 | ||
| 19 | - | Parallel.For(0, arr.GetLength(0), x => |
| 19 | + | tempSum += acquisition.frameDataShorts[i]; |
| 20 | } | |
| 21 | - | Parallel.For(0, arr.GetLength(1), y => |
| 21 | + | |
| 22 | - | {
|
| 22 | + | stopWatch.Stop(); |
| 23 | - | max = arr[x, y] > max ? arr[x, y] : max; |
| 23 | + | // Get the elapsed time as a TimeSpan value. |
| 24 | - | min = arr[x, y] < min ? arr[x, y] : min; |
| 24 | + | TimeSpan ts = stopWatch.Elapsed; |