/// <summary>Reads raw grayscale fingerprint image from byte array.</summary>
 /// <remarks>
 /// <para>
 /// The image must contain black fingerprint on white background
 /// in resolution specified by <see cref="FingerprintImageOptions.Dpi" />.
 /// </para>
 /// <para>
 /// Pixels are represented as 8-bit unsigned bytes with 0 meaning black and 255 meaning white.
 /// Pixels in <paramref name="pixels" /> array are ordered from top-left to bottom-right in horizontal rows.
 /// Size of <paramref name="pixels" /> must be equal to <c>width * height</c>.
 /// </para>
 /// </remarks>
 /// <param name="width">Width of the image.</param>
 /// <param name="height">Height of the image.</param>
 /// <param name="pixels">Image pixels ordered from top-left to bottom-right in horizontal rows.</param>
 /// <param name="options">Additional information about the image or <c>null</c> for default options.</param>
 /// <exception cref="NullReferenceException">Thrown when <paramref name="pixels" /> is <c>null</c>.</exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Thrown when <paramref name="width" /> or <paramref name="height" /> is not positive
 /// or when <paramref name="pixels" /> length is not <c>width * height</c>.
 /// </exception>
 /// <seealso cref="FingerprintTemplate(byte[])" />
 public FingerprintImage(int width, int height, byte[] pixels, FingerprintImageOptions options = null)
 {
     if (pixels == null)
     {
         throw new ArgumentNullException(nameof(pixels));
     }
     if (width <= 0 || height <= 0 || pixels.Length != width * height)
     {
         throw new ArgumentOutOfRangeException();
     }
     Matrix = new DoubleMatrix(width, height);
     for (int y = 0; y < height; ++y)
     {
         for (int x = 0; x < width; ++x)
         {
             Matrix[x, y] = 1 - pixels[y * width + x] / 255.0;
         }
     }
     if (options == null)
     {
         options = new FingerprintImageOptions();
     }
     Dpi = options.Dpi;
 }
示例#2
0
        public static FingerprintImage Grayscale(int width, int height, byte[] pixels, FingerprintImageOptions options = null)
        {
            if (pixels == null)
            {
                throw new ArgumentNullException(nameof(pixels));
            }
            if (width <= 0 || height <= 0 || pixels.Length != width * height)
            {
                throw new ArgumentOutOfRangeException();
            }
            var matrix = new DoubleMatrix(width, height);

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    matrix[x, y] = 1 - pixels[y * width + x] / 255.0;
                }
            }
            return(new FingerprintImage(matrix, options ?? new FingerprintImageOptions()));
        }
示例#3
0
 FingerprintImage(DoubleMatrix matrix, FingerprintImageOptions options)
 {
     Matrix = matrix;
     Dpi    = options.Dpi;
 }