Пример #1
0
        /// <summary>
        /// Creates a new Leptonica's <see cref="Pix"/> object from the <see cref="Image"/>.
        /// </summary>
        /// <param name="image">The <see cref="Image"/> to convert.</param>
        /// <returns>
        /// The <see cref="Pix"/> object this method creates.
        /// </returns>
        public static Pix FromImage(Image image)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            SafePixHandle handle = NativeMethods.pixCreate(image.Width, image.Height, image.BitsPerPixel);

            try
            {
                NativeMethods.pixSetResolution(handle, image.HorizontalResolution, image.VerticalResolution);

                unsafe
                {
                    uint *dst = (uint *)NativeMethods.pixGetData(handle).ToPointer();
                    int   wpl = NativeMethods.pixGetWpl(handle);

                    fixed(ulong *src = image.Bits)
                    {
                        Arrays.CopyStrides(image.Height, new IntPtr(src), image.Stride8, new IntPtr(dst), wpl * sizeof(uint));

                        int count = image.Height * wpl;

                        BitUtils.BiteSwap(count, dst);

                        if (image.BitsPerPixel < 8)
                        {
                            Vectors.SwapBits(count, image.BitsPerPixel, dst);
                        }
                    }
                }
            }
            catch
            {
                handle?.Dispose();
                throw;
            }

            return(new Pix(handle));
        }
Пример #2
0
        /// <summary>
        /// Normalizes the image intensity by mapping the image so that the background is near the input value <paramref name="bgval"/>.
        /// </summary>
        /// <param name="pixim">The optional 1bpp mask image.</param>
        /// <param name="pixg">The optional 8bpp gray scale version.</param>
        /// <param name="sx">The tile width, in pixels.</param>
        /// <param name="sy">The tile height, in pixels.</param>
        /// <param name="thresh">The threshold for determining foreground.</param>
        /// <param name="mincount">The minimum number of background pixels in tile.</param>
        /// <param name="bgval">The target background value.</param>
        /// <param name="smoothx">The half-width of block convolution kernel width.</param>
        /// <param name="smoothy">The half-width of block convolution kernel height.</param>
        /// <returns>The destination <see cref="Pix"/>.</returns>
        public Pix BackgroundNorm(Pix pixim, Pix pixg, int sx, int sy, int thresh, int mincount, int bgval, int smoothx, int smoothy)
        {
            SafePixHandle pixd = NativeMethods.pixBackgroundNorm(this.handle, pixim?.handle ?? new SafePixHandle(), pixg?.handle ?? new SafePixHandle(), sx, sy, thresh, mincount, bgval, smoothx, smoothy);

            return(new Pix(pixd));
        }
Пример #3
0
        /// <summary>
        /// Normalizes the image intensity by mapping the image so that the background is near the input value <paramref name="bgval"/>.
        /// </summary>
        /// <param name="pixim">The optional 1bpp mask image.</param>
        /// <param name="reduction">The sub sampling image reduction at which morph closings are done; between 2 and 16.</param>
        /// <param name="size">The size of s.e. for the closing; use odd number.</param>
        /// <param name="bgval">The target background value.</param>
        /// <returns>The destination <see cref="Pix"/>.</returns>
        public Pix BackgroundNormMorph(Pix pixim, int reduction, int size, int bgval)
        {
            SafePixHandle pixd = NativeMethods.pixBackgroundNormMorph(this.handle, pixim?.handle ?? new SafePixHandle(), reduction, size, bgval);

            return(new Pix(pixd));
        }
Пример #4
0
 public static extern SafePixHandle pixDistanceFunction(SafePixHandle pix, int connectivity, int outdepth, int boundcond);
Пример #5
0
 public static extern SafePixHandle pixDilateGray(SafePixHandle pix, int hsize, int vsize);
Пример #6
0
 public static extern int pixWriteMemBmp(out IntPtr fdata, out IntPtr fsize, SafePixHandle pix);
Пример #7
0
 public static extern SafeBoxaHandle pixConnComp(SafePixHandle pix, out SafePixaHandle pixa, int connectivity);
Пример #8
0
 public static extern SafePixHandle pixBackgroundNorm(SafePixHandle pixs, SafePixHandle pixim, SafePixHandle pixg, int sx, int sy, int thresh, int mincount, int bgval, int smoothx, int smoothy);
Пример #9
0
 public static extern SafePixHandle pixBackgroundNormMorph(SafePixHandle pixs, SafePixHandle pixim, int reduction, int size, int bgval);
Пример #10
0
 public static extern int pixOtsuAdaptiveThreshold(SafePixHandle pix, int sx, int sy, int smoothx, int smoothy, float scorefract, out SafePixHandle pixth, out SafePixHandle pixd);
Пример #11
0
 public static extern SafePixHandle pixOtsuThreshOnBackgroundNorm(SafePixHandle pix, SafePixHandle pixim, int sx, int sy, int thresh, int mincount, int bgval, int smoothx, int smoothy, float scorefract, out int pthresh);
Пример #12
0
 public static extern int pixGetDimensions(SafePixHandle pix, out int w, out int h, out int d);
Пример #13
0
 public static extern int pixGetWpl(SafePixHandle pix);
Пример #14
0
 public static extern IntPtr pixGetData(SafePixHandle pix);
Пример #15
0
 public static extern int pixGetResolution(SafePixHandle pix, out int xres, out int yres);
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pix"/> class.
 /// </summary>
 /// <param name="handle">The pointer to Leptonica's <see cref="Pix"/> object.</param>
 internal Pix(SafePixHandle handle)
 {
     this.handle = handle;
 }