public void SetMatrix(ObservableMatrixArray <float> matrix) { this.matrix = matrix; if (matrix != null) { int matrix_size = (int)Math.Sqrt(matrix.getLastInsertedMatrix().Length); InvokeOnMainThread(() => { this.Text = matrix.MatrixName; }); matrix.OnMatrixAdd += () => mre.Release(); } }
private void OnMatrixProcessComplete(float[,] matrix) { InvokeOnMainThread(() => { listBox1.Items.Clear(); var interpolated = MatrixOperation.BicubicInterpolation(matrix, 32, 32); ip.AddMatrix(interpolated); ip.MatrixName = "32x32 Interpolata"; listBox1.Items.Add(ip); if (base_matrix.CurrentIndex < 50) { base_matrix.AddMatrix(interpolated); } if (dam_matrix.CurrentIndex < 1) { dam_matrix.AddMatrix(interpolated); } base_matrix.MatrixName = "Matrice base " + base_matrix.CurrentIndex; listBox1.Items.Add(base_matrix); var matrix_med_base = MatrixOperation.ApplyOperation(x => { return(System.Linq.Enumerable.Average(x)); }, base_matrix.getLastMatrixes(), 32, 32); var mmd = new ObservableMatrixArray <float>(matrix_med_base); mmd.MatrixName = "Media Base"; listBox1.Items.Add(mmd); var matrix_max_base = MatrixOperation.ApplyOperation(x => { return(System.Linq.Enumerable.Max(x)); }, base_matrix.getLastMatrixes(), 32, 32); var mud = new ObservableMatrixArray <float>(matrix_max_base); mud.MatrixName = "Max Base"; listBox1.Items.Add(mud); var matrix_std_base = MatrixOperation.ApplyOperation((x, i, j) => { double sigma = 0; for (int k = 0; k < x.Length; k++) { sigma += Math.Pow(x[k] - matrix_med_base[i, j], 2); } return((float)Math.Sqrt(sigma / x.Length)); }, base_matrix.getLastMatrixes(), 32, 32); var msb = new ObservableMatrixArray <float>(matrix_std_base); msb.MatrixName = "STD Base"; listBox1.Items.Add(msb); var matrix_without_background = MatrixOperation.ApplyOperation <float, float>(x => { return(x[2] > x[0] + (2 * x[1]) ? x[2] : 0); }, new[] { matrix_max_base, matrix_std_base, interpolated }, 32, 32); mwb.AddMatrix(matrix_without_background); mwb.MatrixName = "Background Eliminato"; listBox1.Items.Add(mwb); var matrix_without_max_background = MatrixOperation.ApplyOperation <float, float>(x => { return(x[1] - x[0] > sensibilita ? x[1] - x[0] : 0); }, new[] { matrix_max_base, interpolated }, 32, 32); mwmb.AddMatrix(matrix_without_max_background); mwmb.MatrixName = "Background Max Eliminato"; listBox1.Items.Add(mwmb); float media = 0; MatrixOperation.ApplyOperation <float, float>(x => { media += x[0]; return(0); }, new[] { matrix_without_max_background }, 32, 32); media /= 1024; var matrix_without_max_background_mean = MatrixOperation.ApplyOperation <float, float>(x => { return(x[0] > media ? x[0] : 0); }, new[] { matrix_without_max_background }, 32, 32); var mwmb01 = new ObservableMatrixArray <float>(matrix_without_max_background_mean); mwmb01.MatrixName = "Background Max Eliminato sopra media"; listBox1.Items.Add(mwmb01); float[,] matrix_without_max_background_cp = new float[32, 32]; for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { matrix_without_max_background_cp[i, j] = matrix_without_max_background[i, j]; } } var centroid = MatrixOperation.CalculateCentroid(matrix_without_max_background_cp); matrix_with_cluster_center = MatrixOperation.ApplyOperation <float, float>((x, i, j) => { //return i == centroid.x && j == centroid.y && x[1] > matrix_med_base[i, j] + (2 * matrix_std_base[i, j]) ? 1 : 0; return(i == centroid.x && j == centroid.y ? 1 : 0); }, new[] { matrix_max_base, interpolated }, 32, 32); var centroids = MatrixOperation.CalculateCentroids(matrix_without_max_background_cp); matrix_with_clusters_center = new float[32, 32]; for (int i = 0; i < centroids.x.Length; i++) { matrix_with_clusters_center[centroids.x[i], centroids.y[i]] = 1; } //Console.WriteLine(centroids.x.Length); mwcc.AddMatrix(matrix_with_clusters_center); mwcc.MatrixName = "Clusters center"; listBox1.Items.Add(mwcc); //TEST X DAMIANO float dam_media = 0; float[] dam_array = new float[1024]; MatrixOperation.ApplyOperation <float, float>((x, i, j) => { dam_array[i + j] = x[0]; return(0); }, new[] { dam_matrix.getLastInsertedMatrix() }); dam_media = dam_array.Skip(1).Take(5).Average() + 8; label3.Text = "DAM MEDIA : " + (dam_media); var dam_matrix_without_max_background = MatrixOperation.ApplyOperation <float, float>((x, i, j) => { return(x[0] > dam_media ? 0 : 1); }, new[] { interpolated }, 32, 32); dam_mwmb01.AddMatrix(dam_matrix_without_max_background); dam_mwmb01.MatrixName = "DAM Background Max Eliminato sopra media"; listBox1.Items.Add(dam_mwmb01); }); }