/// <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)); }
/// <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)); }
/// <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)); }
public static extern SafePixHandle pixDistanceFunction(SafePixHandle pix, int connectivity, int outdepth, int boundcond);
public static extern SafePixHandle pixDilateGray(SafePixHandle pix, int hsize, int vsize);
public static extern int pixWriteMemBmp(out IntPtr fdata, out IntPtr fsize, SafePixHandle pix);
public static extern SafeBoxaHandle pixConnComp(SafePixHandle pix, out SafePixaHandle pixa, int connectivity);
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);
public static extern SafePixHandle pixBackgroundNormMorph(SafePixHandle pixs, SafePixHandle pixim, int reduction, int size, int bgval);
public static extern int pixOtsuAdaptiveThreshold(SafePixHandle pix, int sx, int sy, int smoothx, int smoothy, float scorefract, out SafePixHandle pixth, out SafePixHandle pixd);
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);
public static extern int pixGetDimensions(SafePixHandle pix, out int w, out int h, out int d);
public static extern int pixGetWpl(SafePixHandle pix);
public static extern IntPtr pixGetData(SafePixHandle pix);
public static extern int pixGetResolution(SafePixHandle pix, out int xres, out int yres);
/// <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; }