public static Image <Rgb24> DrawDifferenceSpectrogramDerivedFromSingleTStatistic(string key, LDSpectrogramRGB cs1, LDSpectrogramRGB cs2, double tStatThreshold, double colourGain) { double[,] m1 = cs1.GetNormalisedSpectrogramMatrix(key); //the TEN matrix is subtracted from 1. double[,] m2 = cs2.GetNormalisedSpectrogramMatrix(key); double[,] tStatM = GetTStatisticMatrix(key, cs1, cs2); return(DrawDifferenceSpectrogramDerivedFromSingleTStatistic(key, m1, m2, tStatM, tStatThreshold, colourGain)); }
public static Image DrawDifferenceSpectrogram(LDSpectrogramRGB target, LDSpectrogramRGB reference, double colourGain) { string[] keys = target.ColorMap.Split('-'); double[,] tgtRedM = target.GetNormalisedSpectrogramMatrix(keys[0]); double[,] tgtGrnM = target.GetNormalisedSpectrogramMatrix(keys[1]); double[,] tgtBluM = target.GetNormalisedSpectrogramMatrix(keys[2]); double[,] refRedM = reference.GetNormalisedSpectrogramMatrix(keys[0]); double[,] refGrnM = reference.GetNormalisedSpectrogramMatrix(keys[1]); double[,] refBluM = reference.GetNormalisedSpectrogramMatrix(keys[2]); // assume all matricies are normalised and of the same dimensions int rows = tgtRedM.GetLength(0); //number of rows int cols = tgtRedM.GetLength(1); //number Image <Rgb24> bmp = new Image <Rgb24>(cols, rows); int maxRGBValue = 255; for (int row = 0; row < rows; row++) { for (int column = 0; column < cols; column++) { var d1 = (tgtRedM[row, column] - refRedM[row, column]) * colourGain; var d2 = (tgtGrnM[row, column] - refGrnM[row, column]) * colourGain; var d3 = (tgtBluM[row, column] - refBluM[row, column]) * colourGain; var i1 = 127 + Convert.ToInt32(d1 * maxRGBValue); i1 = Math.Max(0, i1); i1 = Math.Min(maxRGBValue, i1); var i2 = 127 + Convert.ToInt32(d2 * maxRGBValue); i2 = Math.Max(0, i2); i2 = Math.Min(maxRGBValue, i2); var i3 = 127 + Convert.ToInt32(d3 * maxRGBValue); i3 = Math.Max(0, i3); i3 = Math.Min(maxRGBValue, i3); //Color colour = Color.FromRgb(i1, i2, i3); bmp[column, row] = Color.FromRgb((byte)i1, (byte)i2, (byte)i3); } } return(bmp); }
public static double[,] GetDifferenceSpectrogramDerivedFromSingleTStatistic(string key, LDSpectrogramRGB cs1, LDSpectrogramRGB cs2, double tStatThreshold) { double[,] m1 = cs1.GetNormalisedSpectrogramMatrix(key); //the TEN matrix is subtracted from 1. double[,] m2 = cs2.GetNormalisedSpectrogramMatrix(key); double[,] tStatM = GetTStatisticMatrix(key, cs1, cs2); int rows = m1.GetLength(0); //number of rows int cols = m2.GetLength(1); //number var differenceM = new double[rows, cols]; for (int row = 0; row < rows; row++) { for (int column = 0; column < cols; column++) { if (Math.Abs(tStatM[row, column]) >= tStatThreshold) { differenceM[row, column] = m1[row, column] - m2[row, column]; } } } return(differenceM); }
public static Image <Rgb24>[] DrawPositiveDifferenceSpectrograms(LDSpectrogramRGB target, LDSpectrogramRGB reference, double colourGain) { string[] keys = target.ColorMap.Split('-'); double[,] tgtRedM = target.GetNormalisedSpectrogramMatrix(keys[0]); double[,] tgtGrnM = target.GetNormalisedSpectrogramMatrix(keys[1]); double[,] tgtBluM = target.GetNormalisedSpectrogramMatrix(keys[2]); double[,] refRedM = reference.GetNormalisedSpectrogramMatrix(keys[0]); double[,] refGrnM = reference.GetNormalisedSpectrogramMatrix(keys[1]); double[,] refBluM = reference.GetNormalisedSpectrogramMatrix(keys[2]); // assume all matricies are normalised and of the same dimensions int rows = tgtRedM.GetLength(0); //number of rows int cols = tgtRedM.GetLength(1); //number var spg1Image = new Image <Rgb24>(cols, rows); var spg2Image = new Image <Rgb24>(cols, rows); int maxRgbValue = 255; for (int row = 0; row < rows; row++) { for (int column = 0; column < cols; column++) { var dR = (tgtRedM[row, column] - refRedM[row, column]) * colourGain; var dG = (tgtGrnM[row, column] - refGrnM[row, column]) * colourGain; var dB = (tgtBluM[row, column] - refBluM[row, column]) * colourGain; var iR1 = 0; var iR2 = 0; var iG1 = 0; var iG2 = 0; var iB1 = 0; var iB2 = 0; var value = Convert.ToInt32(Math.Abs(dR) * maxRgbValue); value = Math.Min(maxRgbValue, value); if (dR > 0.0) { iR1 = value; } else { iR2 = value; } value = Convert.ToInt32(Math.Abs(dG) * maxRgbValue); value = Math.Min(maxRgbValue, value); if (dG > 0.0) { iG1 = value; } else { iG2 = value; } value = Convert.ToInt32(Math.Abs(dB) * maxRgbValue); value = Math.Min(maxRgbValue, value); if (dB > 0.0) { iB1 = value; } else { iB2 = value; } var colour1 = Color.FromRgb((byte)iR1, (byte)iG1, (byte)iB1); var colour2 = Color.FromRgb((byte)iR2, (byte)iG2, (byte)iB2); spg1Image[column, row] = colour1; spg2Image[column, row] = colour2; } } return(new[] { spg1Image, spg2Image }); }
public static Image <Rgb24> DrawDistanceSpectrogram(LDSpectrogramRGB cs1, LDSpectrogramRGB cs2) { string[] keys = cs1.ColorMap.Split('-'); string key = keys[0]; double[,] m1Red = cs1.GetNormalisedSpectrogramMatrix(key); IndexDistributions.SpectralStats stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m1Red); cs1.IndexStats.Add(key, stats); m1Red = MatrixTools.Matrix2ZScores(m1Red, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("1.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); key = keys[1]; double[,] m1Grn = cs1.GetNormalisedSpectrogramMatrix(key); stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m1Grn); cs1.IndexStats.Add(key, stats); m1Grn = MatrixTools.Matrix2ZScores(m1Grn, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("1.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); key = keys[2]; double[,] m1Blu = cs1.GetNormalisedSpectrogramMatrix(key); stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m1Blu); cs1.IndexStats.Add(key, stats); m1Blu = MatrixTools.Matrix2ZScores(m1Blu, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("1.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); key = keys[0]; double[,] m2Red = cs2.GetNormalisedSpectrogramMatrix(key); stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m2Red); cs2.IndexStats.Add(key, stats); m2Red = MatrixTools.Matrix2ZScores(m2Red, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("2.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); key = keys[1]; double[,] m2Grn = cs2.GetNormalisedSpectrogramMatrix(key); stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m2Grn); cs2.IndexStats.Add(key, stats); m2Grn = MatrixTools.Matrix2ZScores(m2Grn, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("2.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); key = keys[2]; double[,] m2Blu = cs2.GetNormalisedSpectrogramMatrix(key); stats = IndexDistributions.GetModeAndOneTailedStandardDeviation(m2Blu); cs2.IndexStats.Add(key, stats); m2Blu = MatrixTools.Matrix2ZScores(m2Blu, stats.Mode, stats.StandardDeviation); ////LoggedConsole.WriteLine("2.{0}: Min={1:f2} Max={2:f2} Mode={3:f2}+/-{4:f3} (SD=One-tailed)", key, dict["min"], dict["max"], dict["mode"], dict["sd"]); var v1 = new double[3]; double[] mode1 = { cs1.IndexStats[keys[0]].Mode, cs1.IndexStats[keys[1]].Mode, cs1.IndexStats[keys[2]].Mode, }; double[] stDv1 = { cs1.IndexStats[keys[0]].StandardDeviation, cs1.IndexStats[keys[1]].StandardDeviation, cs1.IndexStats[keys[2]].StandardDeviation, }; LoggedConsole.WriteLine( "1: avACI={0:f3}+/-{1:f3}; avTEN={2:f3}+/-{3:f3}; avCVR={4:f3}+/-{5:f3}", mode1[0], stDv1[0], mode1[1], stDv1[1], mode1[2], stDv1[2]); var v2 = new double[3]; double[] mode2 = { cs2.IndexStats[keys[0]].Mode, cs2.IndexStats[keys[1]].Mode, cs2.IndexStats[keys[2]].Mode, }; double[] stDv2 = { cs2.IndexStats[keys[0]].StandardDeviation, cs2.IndexStats[keys[1]].StandardDeviation, cs2.IndexStats[keys[2]].StandardDeviation, }; LoggedConsole.WriteLine( "2: avACI={0:f3}+/-{1:f3}; avTEN={2:f3}+/-{3:f3}; avCVR={4:f3}+/-{5:f3}", mode2[0], stDv2[0], mode2[1], stDv2[1], mode2[2], stDv2[2]); // assume all matrices are normalised and of the same dimensions int rows = m1Red.GetLength(0); // number of rows int cols = m1Red.GetLength(1); // number var d12Matrix = new double[rows, cols]; var d11Matrix = new double[rows, cols]; var d22Matrix = new double[rows, cols]; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { v1[0] = m1Red[row, col]; v1[1] = m1Grn[row, col]; v1[2] = m1Blu[row, col]; v2[0] = m2Red[row, col]; v2[1] = m2Grn[row, col]; v2[2] = m2Blu[row, col]; d12Matrix[row, col] = DataTools.EuclideanDistance(v1, v2); d11Matrix[row, col] = (v1[0] + v1[1] + v1[2]) / 3; // get average of the normalised values d22Matrix[row, col] = (v2[0] + v2[1] + v2[2]) / 3; // following lines are for debugging purposes // if ((row == 150) && (col == 1100)) // { // LoggedConsole.WriteLine("V1={0:f3}, {1:f3}, {2:f3}", v1[0], v1[1], v1[2]); // LoggedConsole.WriteLine("V2={0:f3}, {1:f3}, {2:f3}", v2[0], v2[1], v2[2]); // LoggedConsole.WriteLine("EDist12={0:f4}; ED11={1:f4}; ED22={2:f4}", d12Matrix[row, col], d11Matrix[row, col], d22Matrix[row, col]); // } } } double[] array = DataTools.Matrix2Array(d12Matrix); NormalDist.AverageAndSD(array, out var avDist, out var sdDist); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { d12Matrix[row, col] = (d12Matrix[row, col] - avDist) / sdDist; } } double zScore; Dictionary <string, Color> colourChart = GetDifferenceColourChart(); Color colour; var bmp = new Image <Rgb24>(cols, rows); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { zScore = d12Matrix[row, col]; if (d11Matrix[row, col] >= d22Matrix[row, col]) { if (zScore > 3.08) { colour = colourChart["+99.9%"]; } // 99.9% conf else { if (zScore > 2.33) { colour = colourChart["+99.0%"]; } // 99.0% conf else { if (zScore > 1.65) { colour = colourChart["+95.0%"]; } // 95% conf else { if (zScore < 0.0) { colour = colourChart["NoValue"]; } else { // v = Convert.ToInt32(zScore * MaxRGBValue); // colour = Color.FromRgb(v, 0, v); colour = colourChart["+NotSig"]; } } } } // if() else bmp[col, row] = colour; } else { if (zScore > 3.08) { colour = colourChart["-99.9%"]; } // 99.9% conf else { if (zScore > 2.33) { colour = colourChart["-99.0%"]; } // 99.0% conf else { if (zScore > 1.65) { colour = colourChart["-95.0%"]; } // 95% conf else { if (zScore < 0.0) { colour = colourChart["NoValue"]; } else { // v = Convert.ToInt32(zScore * MaxRGBValue); // if() // colour = Color.FromRgb(0, v, v); colour = colourChart["-NotSig"]; } } } } // if() else bmp[col, row] = colour; } } // all rows } // all rows return(bmp); }