コード例 #1
0
        public static Image <Rgb24> Frame3DSpectrogram(Image <Rgb24> image, string key, int value, int year, string colorMap, TimeSpan xInterval, int nyquistFreq, int unitValue, FileInfo sunriseSetData)
        {
            if (key == KeyDayOfYear)
            {
                var title    = string.Format("SPECTROGRAM (hours x Herz): {0}={1}      (R-G-B={2})", key, value, colorMap, unitValue);
                var titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, image.Width);
                return(FrameSliceOf3DSpectrogram_DayOfYear(image, titleBar, year, value, xInterval, unitValue, sunriseSetData, nyquistFreq));
            }
            else
            if (key == KeyFreqBin)
            {
                var title    = string.Format("SPECTROGRAM (hours x months): {0}={1}      (R-G-B={2})", key, value, colorMap, unitValue);
                var titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, image.Width);
                return(FrameSliceOf3DSpectrogram_ConstantFreq(image, titleBar, xInterval, unitValue, sunriseSetData, nyquistFreq));
            }
            else
            if (key == KeyMinOfDay)
            {
                var title    = string.Format("SPECTROGRAM (months x Herz): {0}={1}       (R-G-B={2})", key, value, colorMap, unitValue);
                var titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, image.Width);
                return(FrameSliceOf3DSpectrogram_ConstantMin((Image <Rgb24>)image, titleBar, nyquistFreq, unitValue, sunriseSetData));
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// This method compares the acoustic indices derived from two different long duration recordings of the same length.
        /// It takes as input six csv files of acoustic indices in spectrogram columns, three csv files for each of the original recordings to be compared.
        /// The method produces one spectrogram image files:
        /// 1) A false-colour difference spectrogram, where the difference is shown as a plus/minus departure from grey.
        /// </summary>
        public static void DrawDifferenceSpectrogram(DirectoryInfo ipdir, FileInfo ipFileName1, FileInfo ipFileName2, DirectoryInfo opdir)
        {
            var cs1 = new LDSpectrogramRGB(minuteOffset, xScale, sampleRate, frameWidth, colorMap)
            {
                FileName         = ipFileName1.Name,
                ColorMode        = colorMap,
                BackgroundFilter = backgroundFilterCoeff,
            };

            string[] keys = colorMap.Split('-');
            cs1.ReadCsvFiles(ipdir, ipFileName1.Name, keys);
            if (cs1.GetCountOfSpectrogramMatrices() == 0)
            {
                LoggedConsole.WriteLine("There are no spectrogram matrices in cs1.dictionary.");
                return;
            }

            var cs2 = new LDSpectrogramRGB(minuteOffset, xScale, sampleRate, frameWidth, colorMap)
            {
                FileName         = ipFileName2.Name,
                ColorMode        = colorMap,
                BackgroundFilter = backgroundFilterCoeff,
            };

            cs2.ReadCsvFiles(ipdir, ipFileName2.Name, keys);
            if (cs2.GetCountOfSpectrogramMatrices() == 0)
            {
                LoggedConsole.WriteLine("There are no spectrogram matrices in cs2.dictionary.");
                return;
            }

            //string title1 = String.Format("DIFFERENCE SPECTROGRAM ({0} - {1})      (scale:hours x kHz)       (colour: R-G-B={2})", ipFileName1, ipFileName2, cs1.ColorMODE);
            //Image deltaSp1 = LDSpectrogramDifference.DrawDifferenceSpectrogram(cs1, cs2, colourGain);
            //Image titleBar1 = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title1, deltaSp1.Width, SpectrogramConstants.HEIGHT_OF_TITLE_BAR);
            //deltaSp1 = LDSpectrogramRGB.FrameSpectrogram(deltaSp1, titleBar1, minuteOffset, cs1.X_interval, cs1.Y_interval);
            //string opFileName1 = ipFileName1 + ".Difference.COLNEG.png";
            //deltaSp1.Save(Path.Combine(opdir.FullName, opFileName1));

            //Draw positive difference spectrograms in one image.
            double colourGain = 2.0;

            Image <Rgb24>[] images = DrawPositiveDifferenceSpectrograms(cs1, cs2, colourGain);

            int    nyquist      = cs1.SampleRate / 2;
            int    herzInterval = 1000;
            string title        =
                $"DIFFERENCE SPECTROGRAM where {ipFileName1} > {ipFileName2}.      (scale:hours x kHz)       (colour: R-G-B={cs1.ColorMode})";
            var titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, images[0].Width);

            images[0] = LDSpectrogramRGB.FrameLDSpectrogram(images[0], titleBar, cs1, nyquist, herzInterval);

            title     = string.Format("DIFFERENCE SPECTROGRAM where {1} > {0}      (scale:hours x kHz)       (colour: R-G-B={2})", ipFileName1, ipFileName2, cs1.ColorMode);
            titleBar  = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, images[1].Width);
            images[1] = LDSpectrogramRGB.FrameLDSpectrogram(images[1], titleBar, cs1, nyquist, herzInterval);
            Image  combinedImage = ImageTools.CombineImagesVertically(images);
            string opFileName    = ipFileName1 + "-" + ipFileName2 + ".Difference.png";

            combinedImage.Save(Path.Combine(opdir.FullName, opFileName));
        }
コード例 #3
0
        public static Image DrawFalseColorSpectrograms(Arguments args, string fileStem, Dictionary <string, IndexProperties> indexProperties, Dictionary <string, double[, ]> spectra = null)
        {
            // note: the spectra are oriented as per visual orientation, i.e. xAxis = time framesDictionary<string, Int16>.KeyCollection keys = AuthorList.Keys
            // string[] keys = spectra.Keys.ToCommaSeparatedList().Split(',');
            // int frameCount = spectra[keys[0]].GetLength(1);

            int    sampleRate       = 22050;
            int    frameWidth       = 512;
            double backgroundFilter = 0.75;  // 0.75 means small values are accentuated.
            var    minuteOffset     = TimeSpan.Zero;
            var    dataScale        = args.TemporalScale;
            string colorMap         = args.ColourMap1 ?? LDSpectrogramRGB.DefaultColorMap1;
            var    cs1 = new LDSpectrogramRGB(minuteOffset, dataScale, sampleRate, frameWidth, colorMap)
            {
                FileName                 = fileStem,
                BackgroundFilter         = backgroundFilter,
                IndexCalculationDuration = dataScale,
            };

            // set the relevant dictionary of index properties
            cs1.SetSpectralIndexProperties(indexProperties);
            cs1.SpectrogramMatrices = spectra;

            // get parameter from the config file.
            var configFile           = args.FalseColourSpectrogramConfig.ToFileInfo();
            var config               = LdSpectrogramConfig.ReadYamlToConfig(configFile);
            var blueEnhanceParameter = config.BlueEnhanceParameter ?? 0.0;

            var image1       = cs1.DrawFalseColorSpectrogramChromeless("NEGATIVE", colorMap, blueEnhanceParameter);
            var fullDuration = TimeSpan.FromSeconds(image1.Width * dataScale.TotalSeconds);

            string title       = fileStem;
            var    titleImage  = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, image1.Width);
            int    trackHeight = 20;
            var    timeScale   = ImageTrack.DrawTimeRelativeTrack(fullDuration, image1.Width, trackHeight);

            colorMap = args.ColourMap2 ?? LDSpectrogramRGB.DefaultColorMap2;
            var image2 = cs1.DrawFalseColorSpectrogramChromeless("NEGATIVE", colorMap, blueEnhanceParameter);
            var list   = new List <Image> {
                titleImage, image1, timeScale, image2
            };
            var combinedImage = ImageTools.CombineImagesVertically(list.ToArray());

            return(combinedImage);
        }
コード例 #4
0
        public static Image DrawTStatisticSpectrogramsOfMultipleIndices(LDSpectrogramRGB cs1, LDSpectrogramRGB cs2, double tStatThreshold, double colourGain)
        {
            string[] keys = cs1.ColorMap.Split('-'); //assume both spectorgrams have the same acoustic indices in same order

            double[,] m1 = GetDifferenceSpectrogramDerivedFromSingleTStatistic(keys[0], cs1, cs2, tStatThreshold);
            double[,] m2 = GetDifferenceSpectrogramDerivedFromSingleTStatistic(keys[1], cs1, cs2, tStatThreshold);
            double[,] m3 = GetDifferenceSpectrogramDerivedFromSingleTStatistic(keys[2], cs1, cs2, tStatThreshold);

            int rows = m1.GetLength(0); //number of rows
            int cols = m1.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 = m1[row, column] * colourGain;
                    var dG = m2[row, column] * colourGain;
                    var dB = m3[row, column] * colourGain;

                    byte iR1 = 0;
                    byte iR2 = 0;
                    byte iG1 = 0;
                    byte iG2 = 0;
                    byte iB1 = 0;
                    byte iB2 = 0;

                    var value = Convert.ToByte(Math.Abs(dR) * maxRgbValue);
                    value = (byte)Math.Min(maxRgbValue, value);
                    if (dR > 0.0)
                    {
                        iR1 = value;
                    }
                    else
                    {
                        iR2 = value;
                    }

                    value = Convert.ToByte(Math.Abs(dG) * maxRgbValue);
                    value = (byte)Math.Min(maxRgbValue, value);
                    if (dG > 0.0)
                    {
                        iG1 = value;
                    }
                    else
                    {
                        iG2 = value;
                    }

                    value = Convert.ToByte(Math.Abs(dB) * maxRgbValue);
                    value = (byte)Math.Min(maxRgbValue, value);
                    if (dB > 0.0)
                    {
                        iB1 = value;
                    }
                    else
                    {
                        iB2 = value;
                    }

                    var colour1 = Color.FromRgb(iR1, iG1, iB1);
                    var colour2 = Color.FromRgb(iR2, iG2, iB2);
                    spg1Image[column, row] = colour1;
                    spg2Image[column, row] = colour2;
                }
            }

            var images       = new Image <Rgb24> [2];
            int nyquist      = cs1.SampleRate / 2;
            int herzInterval = 1000;

            string title    = string.Format("DIFFERENCE SPECTROGRAM (thresholded by t-Statistic={2}) where {0} > {1}      (scale:hours x kHz)       (colour: R-G-B={2})", cs1.FileName, cs2.FileName, tStatThreshold);
            var    titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, spg1Image.Width);

            images[0] = LDSpectrogramRGB.FrameLDSpectrogram(spg1Image, titleBar, cs1, nyquist, herzInterval);
            title     = string.Format("DIFFERENCE SPECTROGRAM (thresholded by t-Statistic={2}) where {1} > {0}      (scale:hours x kHz)       (colour: R-G-B={2})", cs1.FileName, cs2.FileName, tStatThreshold);
            titleBar  = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, spg2Image.Width);
            images[1] = LDSpectrogramRGB.FrameLDSpectrogram(spg2Image, titleBar, cs1, nyquist, herzInterval);

            var compositeImage = ImageTools.CombineImagesVertically(images);

            return(compositeImage);
        }
コード例 #5
0
        /// <summary>
        /// This method compares the acoustic indices derived from two different long duration recordings of the same length.
        ///     It takes as input any number of csv files of acoustic indices in spectrogram columns.
        ///     Typically there will be at least three indices csv files for each of the original recordings to be compared.
        ///     The method produces four spectrogram image files:
        ///     1) A negative false-color spectrogram derived from the indices of recording 1.
        ///     2) A negative false-color spectrogram derived from the indices of recording 2.
        ///     3) A spectrogram of euclidean distances between the two input files.
        ///     4) The above three spectrograms combined in one image.
        /// </summary>
        public static void DrawDistanceSpectrogram(
            DirectoryInfo inputDirectory,
            FileInfo inputFileName1,
            FileInfo inputFileName2,
            DirectoryInfo outputDirectory)
        {
            // PARAMETERS
            string outputFileName1 = inputFileName1.Name;
            var    cs1             = new LDSpectrogramRGB(minuteOffset, xScale, sampleRate, frameWidth, colorMap);

            cs1.ColorMode        = colorMap;
            cs1.BackgroundFilter = backgroundFilterCoeff;
            string[] keys = colorMap.Split('-');
            cs1.ReadCsvFiles(inputDirectory, inputFileName1.Name, keys);
            double blueEnhanceParameter = 0.0;

            cs1.DrawNegativeFalseColorSpectrogram(outputDirectory, outputFileName1, blueEnhanceParameter);
            string imagePath = Path.Combine(outputDirectory.FullName, outputFileName1 + ".COLNEG.png");
            var    spg1Image = Image.Load <Rgb24>(imagePath);

            if (spg1Image == null)
            {
                LoggedConsole.WriteLine("SPECTROGRAM IMAGE DOES NOT EXIST: {0}", imagePath);
                return;
            }

            int nyquist       = cs1.SampleRate / 2;
            int hertzInterval = 1000;

            string title =
                $"FALSE COLOUR SPECTROGRAM: {inputFileName1}.      (scale:hours x kHz)       (colour: R-G-B={cs1.ColorMode})";
            var titleBar = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, spg1Image.Width);

            spg1Image = LDSpectrogramRGB.FrameLDSpectrogram(
                spg1Image,
                titleBar,
                cs1,
                nyquist,
                hertzInterval);

            string outputFileName2 = inputFileName2.Name;
            var    cs2             = new LDSpectrogramRGB(minuteOffset, xScale, sampleRate, frameWidth, colorMap)
            {
                ColorMode        = colorMap,
                BackgroundFilter = backgroundFilterCoeff,
            };

            cs2.ReadCsvFiles(inputDirectory, inputFileName2.Name, keys);

            // cs2.DrawGreyScaleSpectrograms(opdir, opFileName2);
            cs2.DrawNegativeFalseColorSpectrogram(outputDirectory, outputFileName2, blueEnhanceParameter);
            imagePath = Path.Combine(outputDirectory.FullName, outputFileName2 + ".COLNEG.png");
            var spg2Image = Image.Load <Rgb24>(imagePath);

            if (spg2Image == null)
            {
                LoggedConsole.WriteLine("SPECTROGRAM IMAGE DOES NOT EXIST: {0}", imagePath);
                return;
            }

            title =
                $"FALSE COLOUR SPECTROGRAM: {inputFileName2}.      (scale:hours x kHz)       (colour: R-G-B={cs2.ColorMode})";
            titleBar  = LDSpectrogramRGB.DrawTitleBarOfFalseColourSpectrogram(title, spg2Image.Width);
            spg2Image = LDSpectrogramRGB.FrameLDSpectrogram(
                spg2Image,
                titleBar,
                cs1,
                nyquist,
                hertzInterval);

            string outputFileName4 = inputFileName1 + ".EuclideanDistance.png";
            var    deltaSp         = DrawDistanceSpectrogram(cs1, cs2);

            Color[] colorArray = LDSpectrogramRGB.ColourChart2Array(GetDifferenceColourChart());
            titleBar = DrawTitleBarOfEuclidianDistanceSpectrogram(
                inputFileName1.Name,
                inputFileName2.Name,
                colorArray,
                deltaSp.Width,
                SpectrogramConstants.HEIGHT_OF_TITLE_BAR);
            deltaSp = LDSpectrogramRGB.FrameLDSpectrogram(deltaSp, titleBar, cs2, nyquist, hertzInterval);
            deltaSp.Save(Path.Combine(outputDirectory.FullName, outputFileName4));

            string outputFileName5 = inputFileName1 + ".2SpectrogramsAndDistance.png";

            var combinedImage = ImageTools.CombineImagesVertically(spg1Image, spg2Image, deltaSp);

            combinedImage.Save(Path.Combine(outputDirectory.FullName, outputFileName5));
        }