public List <bool[]> CreateFingerprintsFromLogSpectrum(
            double[][] logarithmizedSpectrum, IStride stride, int fingerprintLength, int overlap, int topWavelets)
        {
            DbgTimer t = new DbgTimer();

            t.Start();

            // Cut the logaritmic spectrogram into smaller spectrograms with one stride between each
            List <double[][]> spectralImages = SpectrumService.CutLogarithmizedSpectrum(logarithmizedSpectrum, stride, fingerprintLength, overlap);

            // Then apply the wavelet transform on them to later reduce the resolution
            // do this in place
            WaveletService.ApplyWaveletTransformInPlace(spectralImages);

            // Then for each of the wavelet reduce the resolution by only keeping the top wavelets
            // and ignore the magnitude of the top wavelets.
            // Instead, we can simply keep the sign of it (+/-).
            // This information is enough to keep the extract perceptual characteristics of a song.
            List <bool[]> fingerprints = new List <bool[]>();

            foreach (var spectralImage in spectralImages)
            {
                bool[] image = FingerprintDescriptor.ExtractTopWavelets(spectralImage, topWavelets);
                fingerprints.Add(image);
            }

            Dbg.WriteLine("Created {1} Fingerprints from Log Spectrum - Execution Time: {0} ms", t.Stop().TotalMilliseconds, fingerprints.Count);
            return(fingerprints);
        }
Esempio n. 2
0
        public Image GetWaveletsImages(
            double[][] spectrum,
            IStride strideBetweenConsecutiveImages,
            int fingerprintLength,
            int overlap,
            int imagesPerRow)
        {
            List <double[][]> spectralImages = spectrumService.CutLogarithmizedSpectrum(
                spectrum, strideBetweenConsecutiveImages, fingerprintLength, overlap);

            waveletService.ApplyWaveletTransformInPlace(spectralImages);

            int width        = spectralImages[0].GetLength(0);
            int height       = spectralImages[0][0].Length;
            int fingersCount = spectralImages.Count;
            int rowCount     = (int)Math.Ceiling((float)fingersCount / imagesPerRow);

            int imageWidth  = (rowCount == 1 ? width + 2 * SpaceBetweenImages : ((imagesPerRow * (width + SpaceBetweenImages)) + SpaceBetweenImages));
            int imageHeight = (rowCount * (height + SpaceBetweenImages)) + SpaceBetweenImages;

            Bitmap image = new Bitmap(imageWidth, imageHeight, PixelFormat.Format16bppRgb565);

            SetBackground(image, Color.White);

            int verticalOffset   = SpaceBetweenImages;
            int horizontalOffset = SpaceBetweenImages;
            int count            = 0;

            foreach (double[][] spectralImage in spectralImages)
            {
                double average = spectralImage.Average(col => col.Average(v => Math.Abs(v)));
                for (int i = 0; i < width /*128*/; i++)
                {
                    for (int j = 0; j < height /*32*/; j++)
                    {
                        Color color = ValueToBlackWhiteColor(spectralImage[i][j], average);
                        image.SetPixel(i + horizontalOffset, j + verticalOffset, color);
                    }
                }

                count++;
                if (count % imagesPerRow == 0)
                {
                    verticalOffset  += height + SpaceBetweenImages;
                    horizontalOffset = SpaceBetweenImages;
                }
                else
                {
                    horizontalOffset += width + SpaceBetweenImages;
                }
            }

            return(image);
        }