Esempio n. 1
0
        internal IEnumerable <Fingerprint> CreateOriginalFingerprintsFromFrames(IEnumerable <Frame> frames, FingerprintConfiguration configuration)
        {
            var fingerprints = new ConcurrentBag <Fingerprint>();
            var images       = frames.ToList();

            if (!images.Any())
            {
                return(Enumerable.Empty <Fingerprint>());
            }

            var length = images.First().Length;

            Parallel.ForEach(images, () => new ushort[length], (frame, loop, cachedIndexes) =>
            {
                float[] rowCols = configuration.OriginalPointSaveTransform != null ? frame.GetImageRowColsCopy() : frame.ImageRowCols;
                waveletDecomposition.DecomposeImageInPlace(rowCols, frame.Rows, frame.Cols, configuration.HaarWaveletNorm);
                RangeUtils.PopulateIndexes(length, cachedIndexes);
                var image = fingerprintDescriptor.ExtractTopWavelets(rowCols, configuration.TopWavelets, cachedIndexes);
                if (!image.IsSilence())
                {
                    fingerprints.Add(new Fingerprint(image, frame.StartsAt, frame.SequenceNumber));
                }

                return(cachedIndexes);
            },
                             cachedIndexes => { });

            return(fingerprints.ToList());
        }
        public Image GetWaveletTransformedImage(float[][] image, IWaveletDecomposition wavelet, double haarWaveletNorm)
        {
            int width  = image[0].Length;
            int height = image.Length;

            float[] transformedImages = new float[width * height];

            for (int i = 0; i < height; ++i)
            {
                for (int j = 0; j < width; ++j)
                {
                    transformedImages[i * width + j] = image[i][j];
                }
            }

            wavelet.DecomposeImageInPlace(transformedImages, height, width, haarWaveletNorm);

            Bitmap transformed = new Bitmap(width, height, PixelFormat.Format16bppRgb565);

            for (int i = 0; i < transformed.Height; i++)
            {
                for (int j = 0; j < transformed.Width; j++)
                {
                    transformed.SetPixel(j, i, Color.FromArgb((int)image[i][j]));
                }
            }

            return(transformed);
        }
Esempio n. 3
0
        private List <Fingerprint> CreateFingerprintsFromLogSpectrum(IEnumerable <SpectralImage> spectralImages, FingerprintConfiguration configuration)
        {
            var fingerprints = new ConcurrentBag <Fingerprint>();

            Parallel.ForEach(spectralImages, spectralImage =>
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image);
                bool[] image = fingerprintDescriptor.ExtractTopWavelets(spectralImage.Image, configuration.TopWavelets);
                if (!IsSilence(image))
                {
                    fingerprints.Add(new Fingerprint(image, spectralImage.StartsAt, spectralImage.SequenceNumber));
                }
            });

            return(fingerprints.ToList());
        }
        public Image GetWaveletsImages(List <SpectralImage> spectralImages, int imagesPerRow, double haarWaveletNorm)
        {
            foreach (var spectralImage in spectralImages)
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image, spectralImage.Rows, spectralImage.Cols, haarWaveletNorm);
            }

            int    width        = spectralImages[0].Rows;
            int    height       = spectralImages[0].Cols;
            int    fingersCount = spectralImages.Count;
            int    rowCount     = (int)System.Math.Ceiling((float)fingersCount / imagesPerRow);
            int    imageWidth   = (imagesPerRow * (width + PixelsBetweenImages)) + PixelsBetweenImages;
            int    imageHeight  = (rowCount * (height + PixelsBetweenImages)) + PixelsBetweenImages;
            Bitmap image        = new Bitmap(imageWidth, imageHeight, PixelFormat.Format16bppRgb565);

            SetBackground(image, Color.White);

            int verticalOffset   = PixelsBetweenImages;
            int horizontalOffset = PixelsBetweenImages;
            int count            = 0;

            foreach (float[][] spectralImage in spectralImages.Select(Transform2D))
            {
                for (int i = 0; i < width /*128*/; i++)
                {
                    for (int j = 0; j < height /*32*/; j++)
                    {
                        Color color = ValueToBlackWhiteColor(spectralImage[i][j]);
                        image.SetPixel(i + horizontalOffset, j + verticalOffset, color);
                    }
                }

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

            return(image);
        }
Esempio n. 5
0
        public void StandardDecompositionTest()
        {
            const int Rows = 128;
            const int Cols = 32;

            float[][] frames       = new float[Rows][];
            float[]   concatenated = new float[Rows * Cols];
            for (int i = 0; i < Rows; i++)
            {
                frames[i] = TestUtilities.GenerateRandomSingleArray(Cols);
                Buffer.BlockCopy(frames[i], 0, concatenated, sizeof(float) * i * Cols, sizeof(float) * Cols);
            }

            AssertAreSame(Rows, Cols, frames, concatenated);
            waveletDecomposition.DecomposeImageInPlace(concatenated, Rows, Cols, 1d);
            DecomposeImageLocal(frames);
            AssertAreSame(Rows, Cols, frames, concatenated);
        }
Esempio n. 6
0
        public Image GetWaveletTransformedImage(double[][] image, IWaveletDecomposition wavelet)
        {
            int width  = image[0].Length;
            int height = image.Length;

            wavelet.DecomposeImageInPlace(image);
            Bitmap transformed = new Bitmap(width, height, PixelFormat.Format16bppRgb565);

            for (int i = 0; i < transformed.Height; i++)
            {
                for (int j = 0; j < transformed.Width; j++)
                {
                    transformed.SetPixel(j, i, Color.FromArgb((int)image[i][j]));
                }
            }

            return(transformed);
        }
        private List <Fingerprint> CreateFingerprintsFromLogSpectrum(IEnumerable <SpectralImage> spectralImages, FingerprintConfiguration configuration)
        {
            var fingerprints = new List <Fingerprint>();

            foreach (var spectralImage in spectralImages)
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image);
                bool[] image = fingerprintDescriptor.ExtractTopWavelets(spectralImage.Image, configuration.TopWavelets);
                if (!IsSilence(image))
                {
                    fingerprints.Add(new Fingerprint {
                        Signature = image, Timestamp = spectralImage.Timestamp, SequenceNumber = spectralImage.SequenceNumber
                    });
                }
            }

            return(fingerprints);
        }
Esempio n. 8
0
        public List <Fingerprint> CreateFingerprintsFromLogSpectrum(IEnumerable <SpectralImage> spectralImages, FingerprintConfiguration configuration)
        {
            var fingerprints   = new ConcurrentBag <Fingerprint>();
            var spectrumLength = configuration.SpectrogramConfig.ImageLength * configuration.SpectrogramConfig.LogBins;

            Parallel.ForEach(spectralImages, () => new ushort[spectrumLength], (spectralImage, loop, cachedIndexes) =>
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image, spectralImage.Rows, spectralImage.Cols, configuration.HaarWaveletNorm);
                RangeUtils.PopulateIndexes(spectrumLength, cachedIndexes);
                var image = fingerprintDescriptor.ExtractTopWavelets(spectralImage.Image, configuration.TopWavelets, cachedIndexes);
                if (!image.IsSilence())
                {
                    fingerprints.Add(new Fingerprint(image, spectralImage.StartsAt, spectralImage.SequenceNumber));
                }

                return(cachedIndexes);
            },
                             cachedIndexes => { });

            return(fingerprints.ToList());
        }
Esempio n. 9
0
        public void StandardDecompositionTest()
        {
            const int Rows = 128;
            const int Cols = 32;

            float[][] frames      = new float[Rows][];
            float[][] framesLocal = new float[Rows][];
            for (int i = 0; i < Rows; i++)
            {
                frames[i]      = TestUtilities.GenerateRandomDoubleArray(Cols);
                framesLocal[i] = new float[Cols];
                frames[i].CopyTo(framesLocal[i], 0);
            }

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Cols; j++)
                {
                    Assert.AreEqual(true, (frames[i][j] - framesLocal[i][j]) < 0.00001);
                }
            }

            waveletDecomposition.DecomposeImageInPlace(frames);

            decimal sumFrames = frames.Sum(target => target.Sum(d => (decimal)Math.Abs(d)));

            decimal sumFrameLocal = framesLocal.Sum(target => target.Sum(d => (decimal)Math.Abs(d)));

            Assert.AreEqual(true, Math.Abs(sumFrames - sumFrameLocal) > (decimal)0.1);
            DecomposeImageLocal(framesLocal);
            for (int i = 0; i < Rows; i++)
            {
                for (var j = 0; j < Cols; j++)
                {
                    Assert.AreEqual(true, (frames[i][j] - framesLocal[i][j]) < 0.001);
                }
            }
        }
Esempio n. 10
0
        internal IEnumerable <Fingerprint> CreateOriginalFingerprintsFromFrames(IEnumerable <Frame> frames, FingerprintConfiguration configuration)
        {
            var normalized = configuration.FrameNormalizationTransform.Normalize(frames);
            var blurred    = configuration.GaussianBlurConfiguration.GaussianFilter switch
            {
                GaussianFilter.None => normalized,
                _ => BlurFrames(normalized, configuration.GaussianBlurConfiguration)
            };

            var images = blurred.ToList();

            if (!images.Any())
            {
                return(Enumerable.Empty <Fingerprint>());
            }

            var fingerprints  = new ConcurrentBag <Fingerprint>();
            var length        = images.First().Length;
            var saveTransform = configuration.OriginalPointSaveTransform;

            Parallel.ForEach(images, () => new ushort[length], (frame, loop, cachedIndexes) =>
            {
                byte[] originalPoint = saveTransform(frame);
                float[] rowCols      = frame.ImageRowCols;
                waveletDecomposition.DecomposeImageInPlace(rowCols, frame.Rows, frame.Cols, configuration.HaarWaveletNorm);
                RangeUtils.PopulateIndexes(length, cachedIndexes);
                var image = fingerprintDescriptor.ExtractTopWavelets(rowCols, configuration.TopWavelets, cachedIndexes);
                if (!image.IsSilence())
                {
                    fingerprints.Add(new Fingerprint(image, frame.StartsAt, frame.SequenceNumber, originalPoint));
                }

                return(cachedIndexes);
            },
                             cachedIndexes => { });

            return(fingerprints.ToList());
        }
Esempio n. 11
0
        /// <summary>
        ///   Get wavelet decomposition on an image
        /// </summary>
        /// <param name = "wavelet">Wavelet used</param>
        /// <param name = "image">Image to be decomposed</param>
        /// <returns>New image</returns>
        public static Image GetWaveletTransformation(IWaveletDecomposition wavelet, float[][] image)
        {
            int width = image[0].Length;
            int height = image.Length;
            wavelet.DecomposeImageInPlace(image);
            Bitmap transformed = new Bitmap(width, height, PixelFormat.Format16bppRgb565);
            for (int i = 0; i < transformed.Height; i++)
                for (int j = 0; j < transformed.Width; j++)
                    transformed.SetPixel(j, i, Color.FromArgb((int)image[i][j]));

            return transformed;
        }