UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

1,555 lines (1,405 loc) 143 kB
import type { BitDepth as BitDepth_2 } from 'fast-png'; import { decode as decode_2 } from 'tiff'; import type { PngEncoderOptions } from 'fast-png'; /** * * Calculate a new image that is the sum between the current image and the otherImage. * @param image - Image to which to add. * @param otherImage - Image to add. * @returns The summed image. */ export declare function add(image: Image_2, otherImage: Image_2): Image_2; export declare interface AffineTransform { /** * Translation of source points along x and y axes. */ translation: Point; /** * Clockwise angle in degrees. */ rotation: number; /** * Scaling factor from source to destination. */ scale: number; } /** * Aligns two images by finding the translation that minimizes the mean difference of all channels. * between them. The source image should fit entirely in the destination image. * @param source - Image to align. * @param destination - Image to align to. * @param options - Align images min difference options. * @returns Translation that minimizes the mean difference between the images. * Gives the origin of the source image relatively to the top-left corner of the destination image. */ export declare function alignMinDifference(source: Image_2, destination: Image_2, options?: AlignMinDifferenceOptions): { row: number; column: number; similarity: number; }; export declare interface AlignMinDifferenceOptions { /** * Initial step size by which the images will be translated. * @default `Math.max(Math.round(Math.min(source.width, source.height, Math.max(xSpan, ySpan)) / 10,),1,)` */ startStep?: number; mask?: Mask; } /** * Perform an AND operation on two masks. * @param mask - First mask. * @param otherMask - Second mask. * @param options - And options. * @returns AND of the two masks. */ export declare function and(mask: Mask, otherMask: Mask, options?: AndOptions): Mask; export declare interface AndOptions { /** * Image to which the resulting image has to be put. */ out?: Mask; } /** * Bit depth of the image (nb of bits that encode each value in the image). */ export declare type BitDepth = 1 | 8 | 16; export declare type BitValue = 1 | 0 | boolean; /** * Blur an image. The pixel in the center becomes an average of the surrounding ones. * @param image - Image to blur. * @param options - Blur options. * @returns The blurred image. */ declare function blur_2(image: Image_2, options: BlurOptions): Image_2; export { blur_2 as blur } export declare interface BlurOptions { /** * Width of the blurring matrix, must be an odd integer. */ width: number; /** * Height of the blurring matrix, must be an odd integer. */ height: number; /** * Explicit how to handle the borders. * @default `'reflect101'` */ borderType?: BorderType; /** * Value of the border if BorderType is 'constant'. * @default `0` */ borderValue?: number; /** * Image to which to output. */ out?: Image_2; } export declare interface Border { /** * Refers to the roiID of the contiguous ROI. */ connectedID: number; /** * Length of the border with connectedID. */ length: number; } export declare type BorderInterpolationFunction = (column: number, row: number, channel: number, image: Image_2) => number; export declare const BorderType: { readonly CONSTANT: "constant"; readonly REPLICATE: "replicate"; readonly REFLECT: "reflect"; readonly WRAP: "wrap"; readonly REFLECT_101: "reflect101"; }; export declare type BorderType = (typeof BorderType)[keyof typeof BorderType]; export declare function bottomHat(image: Image_2, options?: BottomHatOptions): Image_2; export declare function bottomHat(image: Mask, options?: BottomHatOptions): Mask; export declare interface BottomHatOptions { /** * 3x3 matrix. The kernel can only have ones and zeros. * Accessing a value: kernel[row][column]. * @default `[[1, 1, 1], [1, 1, 1], [1, 1, 1]]` */ kernel?: number[][]; /** * Number of iterations of the algorithm. * @default `1` */ iterations?: number; } export declare interface Brief { keypoints: OrientedFastKeypoint[]; descriptors: BriefDescriptor[]; } export declare type BriefDescriptor = Uint8Array; export declare interface BruteForceMatchOptions { /** * Whether to sort the matches from best to worst. * @default `false` */ sort?: boolean; /** * Number of best matches to return. * @default `source.length` */ nbBestMatches?: number; } /** * Find the best match for each of the source descriptors using brute force matching. * @param source - Source descriptors. * @param destination - Destination descriptors. * @param options - Brute force amtch options. * @returns The best match for each source descriptor. */ export declare function bruteForceOneMatch(source: BriefDescriptor[], destination: BriefDescriptor[], options?: BruteForceMatchOptions): Match[]; /** * Apply Canny edge detection to an image. * @param image - Image to process. * @param options - Canny edge detection options. * @returns The processed image. */ export declare function cannyEdgeDetector(image: Image_2, options?: CannyEdgeOptions): Mask; export declare interface CannyEdgeOptions { /** * Lower threshold of the gaussian blur (indicates the weak edges to discard). * @default `0.04` */ lowThreshold?: number; /** * Higher threshold of the gaussian blur (indicates the strong edges to keep). Value must be between 0 and 1. * @default `0.1` */ highThreshold?: number; /** * Standard deviation of the gaussian blur (sigma). Value must be between 0 and 1. * @default `{ sigma: 1 }` */ gaussianBlurOptions?: GaussianBlurOptions; /** * Enable/ disable hysteresis steps. * @default `true` */ hysteresis?: boolean; /** * Image to which the resulting image has to be put. */ out?: Mask; } export declare const channelLabels: { readonly GREY: readonly ["Grey"]; readonly GREYA: readonly ["Grey", "Alpha"]; readonly RGB: readonly ["Red", "Green", "Blue"]; readonly RGBA: readonly ["Red", "Green", "Blue", "Alpha"]; readonly BINARY: readonly ["Mask"]; }; export declare type ClampFunction = (value: number) => number; /** * Set the pixels connected to the border of the mask to zero. You can chose to allow corner connection of not with the `allowCorners` option. * @param mask - The mask to process. * @param options - Clear border options. * @returns The image with cleared borders. */ export declare function clearBorder(mask: Mask, options?: ClearBorderOptions): Mask; export declare interface ClearBorderOptions { /** * Consider pixels connected by corners? * @default `false` */ allowCorners?: boolean; /** * Image to which the resulting image has to be put. */ out?: Mask; /** * Clear either white or black area touching the border. * In practice it will invert the color. * @default `'white'` */ color?: 'white' | 'black'; } declare function close_2(image: Image_2, options?: CloseOptions): Image_2; declare function close_2(image: Mask, options?: CloseOptions): Mask; export { close_2 as close } export declare interface CloseOptions { /** * 3x3 matrix. The kernel can only have ones and zeros. * Accessing a value: kernel[row][column]. * @default `[[1, 1, 1], [1, 1, 1], [1, 1, 1]]` */ kernel?: number[][]; /** * Number of iterations of the algorithm. * @default `1` */ iterations?: number; } export declare const colorModels: Record<ImageColorModel, { components: number; alpha: boolean; channels: number; }>; /** * Generate an image with all the ROIs of various colors. * @param roiMapManager - The ROI map manager. * @param options - Color ROIs options. * @returns The colored image. */ export declare function colorRois(roiMapManager: RoiMapManager, options?: ColorRoisOptions): Image_2; export declare interface ColorRoisOptions { /** * Define the color mode to use to color the ROIs. * @default `'binary'` */ mode?: RoisColorMode; /** * Specify which ROIs to color. * @default `'bw'` */ roiKind?: RoiKind; } /** * Compute the convolution of a value of a pixel in an image. * @param column - Column of the pixel. * @param row - Row of the pixel. * @param channel - Channel to process. * @param image - Image to process. * @param kernel - Kernel for the convolutions. * @param interpolateBorder - Function to interpolate the border pixels. * @param options - Compute convolution value options. * @returns The convoluted value. */ export declare function computeConvolutionValue(column: number, row: number, channel: number, image: Image_2, kernel: number[][], interpolateBorder: BorderInterpolationFunction, options?: ComputeConvolutionValueOptions): number; export declare interface ComputeConvolutionValueOptions { /** * Specify wether the return value should not be clamped and rounded. */ returnRawValue?: boolean; /** * If the value has to be clamped, specify the clamping function. */ clamp?: ClampFunction; } /** * Compute the Mean Square Error (MSE) between two images. * The input images can have any number of channels. * @param image - First image. * @param otherImage - Second image. * @returns MSE of the two images. */ export declare function computeMse(image: Image_2, otherImage: Image_2): number; /** * Compute the Peak signal-to-noise ratio (PSNR) between two images. * The larger the PSNR, the more similar the images. * @see {@link https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio} * @param image - First image. * @param otherImage - Second image. * @returns PSNR of the two images in decibels. */ export declare function computePsnr(image: Image_2, otherImage: Image_2): number; /** * Compute the Root Mean Square Error (RMSE) between two images. It is just the square root of the MSE. * @see {@link https://en.wikipedia.org/wiki/Root-mean-square_deviation} * @param image - First image. * @param otherImage - Second image. * @returns RMSE of the two images. */ export declare function computeRmse(image: Image_2, otherImage: Image_2): number; /** * Generate an array of ROIs based on an ROI map manager. * @param roiMapManager - Roi map manager to use. */ export declare function computeRois(roiMapManager: RoiMapManager): void; /** * Compute threshold value for an image using the specified algorithm. * @param image - The grey image. * @param options - Threshold options. * @returns The threshold value for the image. */ export declare function computeThreshold(image: Image_2, options?: ThresholdOptionsAlgorithm): number; /** * Convert Mask to GREY. * @param mask - Mask to convert. * @param newImage - Converted image. */ export declare function convertBinaryToGrey(mask: Mask, newImage: Image_2): void; /** * Convert mask to RGB or RGBA. * @param mask - Mask to convert. * @param newImage - Converted image. */ export declare function convertBinaryToRgb(mask: Mask, newImage: Image_2): void; /** * Convert the bit depth of an image. * @param image - Image to convert. * @param newBitDepth - Bit depth to convert to. * @param options - Convert bit depth options. * @returns Converted image. */ export declare function convertBitDepth(image: Image_2, newBitDepth: BitDepth, options?: ConvertBitDepthOptions): Image_2; export declare interface ConvertBitDepthOptions { /** * Image to which to output. */ out?: Image_2; } /** * Convert image to a different color model. * @param image - Image to convert. * @param colorModel - New color model. * @param options - Convert color options. * @returns The converted image. */ export declare function convertColor(image: Image_2 | Mask, colorModel: ImageColorModel, options?: ConvertColorOptions): Image_2; export declare interface ConvertColorOptions { /** * Image to which to output. */ out?: Image_2; } /** * Convex Hull polygon of a mask. */ export declare interface ConvexHull { /** * Vertices of the convex Hull in clockwise order. */ points: Point[]; /** * Perimeter of the convex Hull. */ perimeter: number; /** * Surface of the convex Hull. */ surface: number; } export declare interface ConvolutionOptions { /** * Specify how the borders should be handled. * @default `'reflect101'` */ borderType?: BorderType; /** * Value of the border if BorderType is 'constant'. * @default `0` */ borderValue?: number | number[]; /** * Whether the kernel should be normalized. * @default `false` */ normalize?: boolean; /** * Image to which to output. */ out?: Image_2; } /** * Copy alpha channel of source to dest. * @param source - Source image. * @param dest - Destination image. */ export declare function copyAlpha(source: Image_2, dest: Image_2): void; export declare function copyTo(source: Image_2, target: Image_2, options?: CopyToOptions<Image_2>): Image_2; export declare function copyTo(source: Mask, target: Mask, options?: CopyToOptions<Mask>): Mask; export declare interface CopyToOptions<OutType> { /** * Origin for the crop relative to the top-left corner of the image. * @default `{row: 0, column: 0}` */ origin?: Point; /** * Image to which to output. */ out?: OutType; } /** * Corrects background from an image for baseline correction. * @param image - Image to subtract background from. * @param options - CorrectBackgroundOptions. * @returns Image with corrected baseline. */ export declare function correctBackground(image: Image_2, options: CorrectBackgroundOptions): Image_2; export declare interface CorrectBackgroundOptions { /** * @param background - Points that are considered the background of an image. */ background: Point[]; /** * @param order - Order of regression function. * @default `2` */ order?: number; /** * Checks if the image background is light or dark. If the background is * light, the output image will be inverted. * @default `'light'` */ backgroundKind?: 'dark' | 'light'; } /** * Correct the colors in an image using the reference colors. * Algorithm is based on the paper "Color correction using improved linear regression algorithm". * DOI: 10.1109/ICTS.2015.7379874. * @param image - Image to process. * @param measuredColors - Colors from the image, which will be compared to the reference. * @param referenceColors - Reference colors. * @returns Image with the colors corrected. */ export declare function correctColor(image: Image_2, measuredColors: RgbColor[], referenceColors: RgbColor[]): Image_2; export declare interface CreateFromOptions extends ImageOptions { width?: number; height?: number; } /** * Crop the input image to a desired size. * @param image - Image to crop. * @param [options] - Crop options. * @returns The new cropped image. * @example * var cropped = image.crop({ * row:20, * column:100 * }); */ export declare function crop(image: Image_2, options?: CropOptions): Image_2; /** * Crops the image based on the alpha channel * This removes lines and columns where the alpha channel is lower than a threshold value. * @param image - Image to process. * @param options - Crop alpha options. * @returns The cropped image. */ export declare function cropAlpha(image: Image_2, options?: CropAlphaOptions): Image_2; export declare interface CropAlphaOptions { /** * Threshold from which rows and columns should be kept. */ threshold?: number; } export declare interface CropOptions { /** * Origin of the crop relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Specify the width of the cropped image. * @default `image.width` */ width?: number; /** * Specify the width of the cropped image. * @default `image.height` */ height?: number; } /** * Crop an oriented rectangle from an image. * If the rectangle's length or width are not an integers, its dimension is expanded in both directions such as the length and width are integers. * @param image - The input image * @param points - The points of the rectangle. Points must be circling around the rectangle (clockwise or anti-clockwise). The validity of the points passed is assumed and not checked. * @param options - Crop options, see {@link CropRectangleOptions} * @returns The cropped image. The orientation of the image is the one closest to the rectangle passed as input. */ export declare function cropRectangle(image: Image_2, points: Point[], options?: CropRectangleOptions): Image_2; export declare type CropRectangleOptions = Omit<TransformOptions, 'width' | 'height' | 'inverse' | 'fullImage'>; /** * Return the indices of pairs the keypoints that are mutually the best match. * This means that if B is the best match for A, A should be the best match for B. * The distance of the resulting matches is the maximum distance between the two. * @param srcDstMatches - Best matches computed from source do destination. * @param dstSrcMatches - Best matches computed from destination to source. * @returns The pairs of keypoints that are mutually the best match. */ export declare function crosscheck(srcDstMatches: Match[], dstSrcMatches: Match[]): Match[]; /** * Decode input data. Data format is automatically detected. * Possible formats: png, jpeg and tiff. * @param data - Data to decode. * @returns The decoded image. */ export declare function decode(data: ArrayBufferView): Image_2; /** * Decode a jpeg. See the jpeg-js npm module. * @param buffer - The data to decode. * @returns The decoded image. */ export declare function decodeJpeg(buffer: Uint8Array): Image_2; /** * Decode a PNG. See the fast-png npm module. * @param buffer - The data to decode. * @returns The decoded image. */ export declare function decodePng(buffer: Uint8Array): Image_2; /** * Decode input data and create stack. Data format is automatically detected. * Possible formats: tiff. * @param data - Data to decode. * @returns The decoded image. */ export declare function decodeStack(data: ArrayBufferView): Stack; /** * Decode a TIFF. See the tiff module. * @param buffer - The data to decode. * @returns The decoded image. */ export declare function decodeTiff(buffer: Uint8Array): Image_2; export declare const defaultPng: EncodeOptionsPng; export declare const DerivativeFilter: { readonly SOBEL: "sobel"; readonly SCHARR: "scharr"; readonly PREWITT: "prewitt"; }; export declare type DerivativeFilter = (typeof DerivativeFilter)[keyof typeof DerivativeFilter]; /** * Apply a derivative filter to an image. * @param image - Image to process. * @param options - Derivative filter options. * @returns The processed image. */ export declare function derivativeFilter(image: Image_2, options?: DerivativeFilterOptions): Image_2; export declare interface DerivativeFilterOptions { /** * Algorithm to use for the derivative filter. * @default `SOBEL` */ filter?: DerivativeFilter; /** * Specify how the borders should be handled. * @default `'replicate'` */ borderType?: BorderType; /** * Value of the border if BorderType is 'constant'. * @default `0` */ borderValue?: number; /** * Specify the bit depth of the resulting image. * @default `image.bitDepth` */ bitDepth?: BitDepth; } export declare function dilate(image: Image_2, options?: DilateOptions): Image_2; export declare function dilate(image: Mask, options?: DilateOptions): Mask; export declare interface DilateOptions { /** * Matrix with odd dimensions (e.g. 1 by 3). The kernel can only have ones and zeros. * Accessing a value: kernel[row][column]. * @default `[[1, 1, 1], [1, 1, 1], [1, 1, 1]]` */ kernel?: number[][]; /** * Number of iterations of the algorithm. * @default `1` */ iterations?: number; } /** * Apply a direct convolution on an image using the specified kernel. The convolution corresponds of a weighted average of the surrounding pixels, the weights being defined in the kernel. * @param image - The image to process. * @param kernel - Kernel to use for the convolution. Should be a 2D matrix with odd number of rows and columns. * @param options - Convolution options. * @returns The convoluted image. */ export declare function directConvolution(image: Image_2, kernel: number[][], options?: ConvolutionOptions): Image_2; /** * * Divides image pixels by a certain value. * @param image - image to which division will be applied. * @param value - Value by which each pixel will be divided. * @param options - Divide options * @returns image. */ export declare function divide(image: Image_2, value: number, options?: DivideOptions): Image_2; export declare interface DivideOptions { /** * Channels where value will be divided. * @default all channels */ channels?: number[]; /** * Image to which the resulting image has to be put. */ out?: Image_2; } /** * Draw a circle defined by center and radius. * @param image - Image to process. * @param center - Circle center point. * @param radius - Circle radius. * @param options - Draw circle options. * @returns The original drawn image. */ export declare function drawCircleOnImage(image: Image_2, center: Point, radius: number, options?: DrawCircleOnImageOptions): Image_2; export declare interface DrawCircleOnImageOptions { /** * Circle border color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ strokeColor?: number[]; /** * Circle fill color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * */ fillColor?: number[]; /** * Image to which the resulting image has to be put. */ out?: Image_2; } export declare function drawKeypoints(image: Image_2, keypoints: FastKeypoint[], options?: DrawKeypointsOptions): Image_2; export declare function drawKeypoints(image: Image_2, keypoints: OrientedFastKeypoint[], options?: DrawOrientedKeypointsOptions): Image_2; export declare interface DrawKeypointsOptions { /** * Origin of the keypoints in the image. * @default `{row: 0, column: 0}` */ origin?: Point; /** * Markers size in pixels. * @default `10` */ markerSize?: number; /** * Keypoint's color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default `[255,0,0]` */ strokeColor?: number[]; /** * Whether to fill the markers. * @default `false` */ fill?: boolean; /** * Whether the score of the keypoints should be reflected in their color. * @default `false` */ showScore?: boolean; /** * Maximal number of matches with smallest distance to draw. * @default `keypoints.length` */ maxNbKeypoints?: number; /** * Image to which the resulting image has to be put. */ out?: Image_2; /** * Options for the coloring of the keypoints depending on their score (useful if showScore = true). */ showScoreOptions?: GetColorsOptions; } /** * Draw a line defined by two points onto an image. * @param image - Image to process. * @param from - Line starting point. * @param to - Line ending point. * @param options - Draw Line options. * @returns The mask with the line drawing. */ export declare function drawLineOnImage(image: Image_2, from: Point, to: Point, options?: DrawLineOnImageOptions): Image_2; export declare interface DrawLineOnImageOptions { /** * Color of the line - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ strokeColor?: number[]; /** * Origin of the line relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Image to which the resulting image has to be put. */ out?: Image_2; } /** * Draw a line defined by two points onto a mask. * @param mask - Mask to process. * @param from - Line starting point. * @param to - Line ending point. * @param options - Draw Line options. * @returns The mask with the line drawing. */ export declare function drawLineOnMask(mask: Mask, from: Point, to: Point, options?: DrawLineOnMaskOptions): Mask; export declare interface DrawLineOnMaskOptions { /** * Origin of the line relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Mask to which the result has to be put. */ out?: Mask; } /** * Draw a marker on the image. * @param image - Image to process. * @param point - Marker center point. * @param options - Draw marker options. * @returns The image with the marker drawing. */ export declare function drawMarker(image: Image_2, point: Point, options: DrawMarkerOptions): Image_2; export declare interface DrawMarkerOptions { /** * Marker size, Odd number greater than 1. * @default `1` */ size?: number; /** * Marker shape. * @default `'cross'` */ shape?: 'circle' | 'triangle' | 'cross' | 'square'; /** * Circle border color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. */ fillColor?: number[]; /** * Circle border color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ strokeColor?: number[]; /** * Image to which the resulting image has to be put. */ out?: Image_2; } /** * Draw markers on the image. * @param image - Image to process. * @param points - Markers center points. * @param options - Draw marker options. * @returns The image with the markers drawing. */ export declare function drawMarkers(image: Image_2, points: Point[], options?: DrawMarkerOptions): Image_2; /** * Draw the the matches between two images on their montage. * @param montage - The montage of two images to match. * @param matches - The matches between source and destination. * @param sourceKeypoints - Source keypoints. * @param destinationKeypoints - Destination keypoints. * @param options - Draw matches options. * @returns The comparison image. */ export declare function drawMatches(montage: Montage, matches: Match[], sourceKeypoints: FastKeypoint[], destinationKeypoints: FastKeypoint[], options?: DrawMatchesOptions): Image_2; export declare interface DrawMatchesOptions { /** * Circles diameter in pixels. * @default `10` */ circleDiameter?: number; /** * Annotations color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default `[255,0,0]` */ strokeColor?: number[]; /** * Whether the matches should be colored depending on the distance. * @default `false` */ showDistance?: boolean; /** * Options for the coloring of the matches depending on their distance (useful if showDistance = true). */ showDistanceOptions?: GetColorsOptions; /** * Maximal number of keypoints with best score to draw. * @default `matches.length` */ maxNbMatches?: number; } export declare interface DrawOrientedKeypointsOptions extends DrawKeypointsOptions { /** * Show the orientation of the keypoints. * @default `false` */ showOrientation?: boolean; } export declare function drawPoints(image: Image_2, points: Point[], options?: DrawPointsOptions): Image_2; export declare function drawPoints(image: Mask, points: Point[], options?: DrawPointsOptions): Mask; export declare interface DrawPointsOptions { /** * Color of the points - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ color?: number[]; /** * Origin of the points relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Image to which the resulting image has to be put. */ out?: Image_2 | Mask; } /** * Draw a polygon defined by an array of points onto an image. * @param image - Image to process. * @param points - Polygon vertices. * @param options - Draw Line options. * @returns The image with the polygon drawing. */ export declare function drawPolygonOnImage(image: Image_2, points: Point[], options?: DrawPolygonOnImageOptions): Image_2; export declare interface DrawPolygonOnImageOptions extends DrawPolylineOnImageOptions { /** * Fill color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ fillColor?: number[]; /** * Origin of the rectangle relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; } /** * Draw a polygon defined by an array of points on a mask. * @param mask - Mask to process. * @param points - Polygon vertices. * @param options - Draw Line options. * @returns The mask with the polygon drawing. */ export declare function drawPolygonOnMask(mask: Mask, points: Point[], options?: DrawPolygonOnMaskOptions): Mask; export declare interface DrawPolygonOnMaskOptions extends DrawPolylineOnMaskOptions { /** * Fill polygon. */ filled?: boolean; /** * Origin of the rectangle relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; } /** * Draw a polyline defined by an array of points on an image. * @param image - Image to process. * @param points - Polyline array of points. * @param options - Draw polyline options. * @returns The image with the polyline drawing. */ export declare function drawPolylineOnImage(image: Image_2, points: Point[], options?: DrawPolylineOnImageOptions): Image_2; export declare interface DrawPolylineOnImageOptions { /** * Line color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ strokeColor?: number[]; /** * Origin of the rectangle relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Image to which the resulting image has to be put. */ out?: Image_2; } /** * Draw a polyline defined by an array of points on an image. * @param mask - Mask to process. * @param points - Polyline array of points. * @param options - Draw polyline options. * @returns The mask with the polyline drawing. */ export declare function drawPolylineOnMask(mask: Mask, points: Point[], options?: DrawPolylineOnMaskOptions): Mask; export declare interface DrawPolylineOnMaskOptions { /** * Origin of the rectangle relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Mask to which the resulting image has to be put. */ out?: Mask; } export declare function drawRectangle(image: Image_2, options?: DrawRectangleOptions<Image_2>): Image_2; export declare function drawRectangle(image: Mask, options?: DrawRectangleOptions<Mask>): Mask; export declare interface DrawRectangleOptions<OutType> { /** * Origin of the rectangle relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; /** * Specify the width of the rectangle. * @default `image.width` */ width?: number; /** * Specify the width of the rectangle. * @default `image.height` */ height?: number; /** * Color of the rectangle's border - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * @default A black pixel. */ strokeColor?: number[]; /** * Rectangle fill color - An array of numerical values, one for each channel of the image. If less values are defined than there are channels in the image, the remaining channels will be set to 0. * */ fillColor?: number[]; /** * Image to which the resulting image has to be put. */ out?: OutType; } export declare interface Ellipse { center: { column: number; row: number; }; majorAxis: { points: [Point, Point]; length: number; angle: number; }; minorAxis: { points: [Point, Point]; length: number; angle: number; }; surface: number; } /** * Encodes the image to the specified format * @param image - Image to encode. * @param options - Format and options passed to the encoder. * @returns The encoded image. */ export declare function encode(image: Image_2 | Mask, options?: EncodeOptionsBmp | EncodeOptionsPng | EncodeOptionsJpeg): Uint8Array; /** * Converts image into Data URL string. * @param image - Image to get base64 encoding from. * @param options - Encoding options. * @returns base64 string. */ export declare function encodeDataURL(image: Image_2, options?: EncodeOptionsBmp | EncodeOptionsPng | EncodeOptionsJpeg): string; /** * Creates a JPEG buffer from an image. * @param image - The image instance. * @param options - JPEG encoding options. * @returns The buffer. */ export declare function encodeJpeg(image: Image_2 | Mask, options?: EncodeJpegOptions): Uint8Array; export declare interface EncodeJpegOptions { /** * Defines jpeg quality. Integer value between 1 and 100%, 100% being the best quality. * @default `50` */ quality?: number; } export declare interface EncodeOptionsBmp { format: 'bmp'; } export declare interface EncodeOptionsJpeg { format: 'jpg' | 'jpeg'; encoderOptions?: EncodeJpegOptions; } export declare interface EncodeOptionsPng { format: 'png'; encoderOptions?: EncodePngOptions; } /** * Creates a PNG buffer from an image. * @param image - The image instance. * @param options - PNG encoding options. * @returns The buffer. */ export declare function encodePng(image: Image_2 | Mask, options?: EncodePngOptions): Uint8Array; export declare type EncodePngOptions = PngEncoderOptions; export declare function erode(image: Image_2, options?: ErodeOptions): Image_2; export declare function erode(image: Mask, options?: ErodeOptions): Mask; export declare interface ErodeOptions { /** * Matrix with odd dimensions (e.g. 1 by 3). The kernel can only have ones and zeros. * Accessing a value: kernel[row][column]. * @default `[[1, 1, 1], [1, 1, 1], [1, 1, 1]]` */ kernel?: number[][]; /** * Number of iterations of the algorithm. * @default `1` */ iterations?: number; } /** * Extend the borders of an image according to the given border type. * @param image - Image to extend. * @param options - Options. * @returns A copy of the image with extended borders. */ export declare function extendBorders(image: Image_2, options: ExtendBordersOptions): Image_2; export declare interface ExtendBordersOptions { /** * Left and right border thickness. */ horizontal: number; /** *Top and bottom border thickness. */ vertical: number; /** * Specify how the borders should be handled. * @default `'reflect101'` */ borderType?: BorderType; /** * Value of the border if BorderType is 'constant'. * @default `0` */ borderValue?: number | number[]; } /** * Extract the pixels of an image, as specified in a mask. * @param image - The image to process. * @param mask - The mask defining which pixels to keep. * @param options - Extract options. * @returns The extracted image. */ export declare function extract(image: Image_2, mask: Mask, options?: ExtractOptions): Image_2; export declare interface ExtractOptions { /** * Origin of the ROI relative to a parent image (top-left corner). * @default `{row: 0, column: 0}` */ origin?: Point; } export declare interface ExtremaOptions { /** * Chooses what kind of extremum to compute. * @default `'maximum'` */ kind?: 'minimum' | 'maximum'; /** * Uses mask to check if a point belongs to a ROI or not * @default `undefined` */ mask?: Mask; /** * Chooses what kind of coverage algorithm to use to compute the extremum. * @default `'star'` */ algorithm?: 'cross' | 'square' | 'star'; /** * Maximum number of points that can be equal to the extremum * @default `2` */ maxEquals?: number; } export declare interface FastKeypoint { /** * Location of the keypoint in the image. */ origin: Point; /** * Score of the keypoint, the bigger it is, the better the feature. * It is the criteria used for the non-maximal suppression. */ score: number; } export declare interface Feret { /** * Smaller Feret diameter. */ minDiameter: FeretDiameter; /** * Bigger Feret diameter. */ maxDiameter: FeretDiameter; /** * Ratio between the smaller and the bigger diameter. * Expresses how elongated the shape is. This is a value between 0 and 1. */ aspectRatio: number; } export declare interface FeretDiameter { /** * Start and end point of the Feret diameter. */ points: Point[]; /** * Length of the diameter. */ length: number; /** * Angle between the diameter and a horizontal line in degrees. */ angle: number; /** * Calliper lines that pass by endpoints of Feret diameters. */ calliperLines: [[Point, Point], [Point, Point]]; } /** * Fetches image URL and decodes it. * @param dataUrl - Image URL. * @returns decoded image data. */ export declare function fetchURL(dataUrl: string): Promise<Image_2>; /** * Apply a flip filter to an image. * @param image - Image to process. * @param options - Flip options. * @returns - The processed image. */ export declare function flip(image: Image_2, options?: FlipOptions): Image_2; export declare interface FlipOptions { /** * Image to which the resulting image has to be put. * @default `'horizontal'` */ axis?: 'horizontal' | 'vertical' | 'both'; /** * Image to which the resulting image has to be put. */ out?: Image_2; } /** * Apply a flood fill algorithm to an image. * @param mask - Mask to process. * @param options - Flood fill options. * @returns The filled mask. */ export declare function floodFill(mask: Mask, options?: FloodFillOptions): Mask; export declare interface FloodFillOptions { /** * Origin for the algorithm relative to the top-left corner of the image. * @default `{row: 0, column: 0}` */ origin?: Point; /** * Consider pixels connected by corners? * @default `false` */ allowCorners?: boolean; /** * Specify the output image. */ out?: Mask; } /** * Extract the ROIs of an image. * @param mask - Mask to extract the ROIs from. * @param options - From mask options. * @returns The corresponding ROI manager. */ export declare function fromMask(mask: Mask, options?: FromMaskOptions): RoiMapManager; export declare interface FromMaskOptions { /** * Consider pixels connected by corners as same ROI? * @default `false` */ allowCorners?: boolean; } /** * Apply a gaussian filter to an image. * @param image - Image to blur. * @param options - Gaussian blur options. * @returns The blurred image. */ export declare function gaussianBlur(image: Image_2, options: GaussianBlurOptions): Image_2; declare interface GaussianBlurBaseOptions { /** * Specify how the borders should be handled. * @default `'reflect101'` */ borderType?: BorderType; /** * Image to which the resulting image has to be put. */ out?: Image_2; } export declare type GaussianBlurOptions = GaussianBlurSigmaOptions | GaussianBlurXYOptions; export declare interface GaussianBlurSigmaOptions extends GaussianBlurBaseOptions { /** * The standard deviation. Specifies the width of the gaussian function in the case where it is the same for x and y. */ sigma: number; /** * Size of the kernel. * @default `2 * Math.ceil(2 * sigma) + 1` */ size?: number; } export declare interface GaussianBlurXYOptions extends GaussianBlurBaseOptions { /** * The standard deviation for the x axis. Specifies the width of the gaussian function along x. */ sigmaX: number; /** * The standard deviation for the y axis. Specifies the width of the gaussian function along y. */ sigmaY: number; /** * Size of the X axis kernel. * @default `2 * Math.ceil(2 * sigmaX) + 1` */ sizeX?: number; /** * Size of the Y axis kernel. * @default `2 * Math.ceil(2 * sigmaY) + 1` */ sizeY?: number; } /** * Get the affine transformation from the source to the destination image. * @param source - Source image. Should be the image to align on the reference image. * It can have an additional margin, specified in the options. * @param destination - Destination image. Should be the reference image. * @param options - Get destination translation options. * @returns The affine transformation from source to destination image. */ export declare function getAffineTransform(source: Image_2, destination: Image_2, options?: GetAffineTransformOptions): GetAffineTransformResult; export declare interface GetAffineTransformOptions { /** * @default `31` */ centroidPatchDiameter?: number; /** * @default `10` */ bestKeypointRadius?: number; /** * Should only the crossckeck matches be considered. * @default `true` */ crosscheck?: boolean; /** * Should the contrast of the images be enhanced before feature matching. * @default `true` */ enhanceContrast?: boolean; /** * Origin of the destination image relative to the top-left corner of the source image. * Roughly indicates the position of the destination image in the source image. Is used * to filter matches by distance as well as to define a subarea of the source image to * use for contrast enhancement. * @default `{ column: 0, row: 0 }` */ destinationOrigin?: Point; /** * Max number of iterations of the ransac algorithm. */ maxRansacNbIterations?: number; /** * Save images with matches for debugging. * @default `false` */ debug?: boolean; /** * Path of the debug image. * @default `${import.meta.dirname}/montage.png` */ debugImagePath?: string; } export declare interface GetAffineTransformResult { /** * Affine transformation from source to destination. */ transform: AffineTransform; stats: { /** * Number of matches of feature matching between source and destination. * The bigger this number is, the better. */ nbMatches: number; /** * Number of inliers resulting from the ransac algorithm. */ nbInliers: number; /** * Number of iterations of the RANSAC algorithm. */ nbRansacIterations: number; /** * Number of source keypoints used for matching. */ nbSourceKeypoints: number; /** * Number of destination keypoints used for matching. */ nbDestinationKeypoints: number; }; } /** * Return the best keypoints within the given radius in pixels. * @param keypoints - Keypoints to process. * @param radius - Minimum distance in pixels between two keypoints. * @returns The filtered keypoints. */ export declare function getBestKeypointsInRadius(keypoints: OrientedFastKeypoint[], radius?: number): OrientedFastKeypoint[]; /** * Return an array with the coordinates of the pixels that are on the border of the ROI. * The reference is the top-left corner of the ROI. * @param roi - ROI to process. * @param options - Get border points options. * @returns The array of border pixels. */ export declare function getBorderPoints(roi: Roi, options?: GetBorderPointsOptions): Point[]; export declare interface GetBorderPointsOptions { /** * Whether to include borders around holes inside the mask. * When `false`, the mask is solid-filled before processing, so only the outer contour is returned. * When `true`, pixels bordering interior holes are returned as well. * @default `false` */ innerBorders?: boolean; /** * Whether to use 8-connectivity instead of 4-connectivity when detecting border pixels. * When `false`, a pixel is considered a border only if at least one of its 4 orthogonal * neighbors (up, down, left, right) is unset. * When `true`, diagonal neighbors are also considered, so a pixel touching an unset pixel * only by a corner is also returned as a border point. * @default `false` */ allowCorners?: boolean; } /** * Generate the rBRIEF descriptors for the desired keypoints of an image. * The rBRIEF descriptors are presented in these articles: * - ORB article: DOI: 10.1109/ICCV.2011.6126544 * - rBRIEF article: DOI: 10.1007/978-3-642-15561-1_56. * @param image - Source image of the keypoints. * @param keypoints - Keypoints for which the descriptors are wanted. * @param options - Get rotated BRIEF descriptors options. * @returns The descriptors for the given keypoints. */ export declare function getBriefDescriptors(image: Image_2, keypoints: OrientedFastKeypoint[], options?: GetBriefDescriptorsOptions): Brief; export declare interface GetBriefDescriptorsOptions { /** * Options to smooth the image patch before comparing pairs of points. * Default values are the ones recommended in the original BRIEF article. * DOI: https://doi.org/10.1007/978-3-642-15561-1_56. */ smoothingOptions?: GaussianBlurSigmaOptions; /** * Options to modify the gaussian distribution used to generate the points to compare. */ pointsDistributionOptions?: Omit<GetGaussianPointsOptions, 'nbPoints'>; /** * Size of the patch around the keypoint used to compute the descriptor. * @default `31` */ patchSize?: number; /** * Number of bits of the final descriptor. Typically a power or 2: 128, 256, 512. * @default `256` */ descriptorLength?: number; } export declare interface GetColorsOptions { /** * Number of shades