/** * @license * Copyright 2021 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ /// /// import { Color, PixelInput, Segmentation } from './interfaces/common_interfaces'; /** * This render_util implementation is based on the body-pix output_rending_util * code found here: * https://github.com/tensorflow/tfjs-models/blob/master/body-pix/src/output_rendering_util.ts * It is adapted to account for the generic segmentation interface. */ declare type ImageType = CanvasImageSource | OffscreenCanvas | PixelInput; declare type Canvas = HTMLCanvasElement | OffscreenCanvas; /** * Given a segmentation or array of segmentations, generates an * image with foreground and background color at each pixel determined by the * corresponding binary segmentation value at the pixel from the output. In * other words, pixels where there is a person will be colored with foreground * color and where there is not a person will be colored with background color. * * @param segmentation Single segmentation or array of segmentations. * * @param foreground Default to {r:0, g:0, b:0, a: 0}. The foreground color * (r,g,b,a) for visualizing pixels that belong to people. * * @param background Default to {r:0, g:0, b:0, a: 255}. The background color * (r,g,b,a) for visualizing pixels that don't belong to people. * * @param drawContour Default to false. Whether to draw the contour around each * person's segmentation mask or body part mask. * * @param foregroundThreshold Default to 0.5. The minimum probability * to color a pixel as foreground rather than background. The alpha channel * integer values will be taken as the probabilities (for more information refer * to `Segmentation` type's documentation). * * @param foregroundMaskValues Default to all mask values. The red channel * integer values that represent foreground (for more information refer to * `Segmentation` type's documentation). * * @returns An ImageData with the same width and height of * the input segmentations, with opacity and * transparency at each pixel determined by the corresponding binary * segmentation value at the pixel from the output. */ export declare function toBinaryMask(segmentation: Segmentation | Segmentation[], foreground?: Color, background?: Color, drawContour?: boolean, foregroundThreshold?: number, foregroundMaskValues?: number[]): Promise; /** * Given a segmentation or array of segmentations, and a function mapping * the red pixel values (representing body part labels) to colours, * generates an image with the corresponding color for each part at each pixel, * and background color used where there is no part. * * @param segmentation Single segmentation or array of segmentations. * * @param maskValueToColor A function mapping red channel mask values to * colors to use in output image. * * @param background Default to {r:0, g:0, b:0, a: 255}. The background color * (r,g,b,a) for visualizing pixels that don't belong to people. * * @param foregroundThreshold Default to 0.5. The minimum probability * to color a pixel as foreground rather than background. The alpha channel * integer values will be taken as the probabilities (for more information refer * to `Segmentation` type's documentation). * * @returns An ImageData with the same width and height of input segmentations, * with the corresponding color for each part at each pixel, and background * pixels where there is no part. */ export declare function toColoredMask(segmentation: Segmentation | Segmentation[], maskValueToColor: (maskValue: number) => Color, background?: Color, foregroundThreshold?: number): Promise; /** * Given an image and a maskImage of type ImageData, draws the image with the * mask on top of it onto a canvas. * * @param canvas The canvas to be drawn onto. * * @param image The original image to apply the mask to. * * @param maskImage An ImageData containing the mask. Ideally this should be * generated by toBinaryMask or toColoredMask. * * @param maskOpacity The opacity of the mask when drawing it on top of the * image. Defaults to 0.7. Should be a float between 0 and 1. * * @param maskBlurAmount How many pixels to blur the mask by. Defaults to 0. * Should be an integer between 0 and 20. * * @param flipHorizontal If the result should be flipped horizontally. Defaults * to false. */ export declare function drawMask(canvas: Canvas, image: ImageType, maskImage: ImageData | null, maskOpacity?: number, maskBlurAmount?: number, flipHorizontal?: boolean): Promise; /** * Given an image and a maskImage of type ImageData, draws the image with the * pixelated mask on top of it onto a canvas. * * @param canvas The canvas to be drawn onto. * * @param image The original image to apply the mask to. * * @param maskImage An ImageData containing the mask. Ideally this should be * generated by toColoredmask. * * @param maskOpacity The opacity of the mask when drawing it on top of the * image. Defaults to 0.7. Should be a float between 0 and 1. * * @param maskBlurAmount How many pixels to blur the mask by. Defaults to 0. * Should be an integer between 0 and 20. * * @param flipHorizontal If the result should be flipped horizontally. Defaults * to false. * * @param pixelCellWidth The width of each pixel cell. Default to 10 px. */ export declare function drawPixelatedMask(canvas: Canvas, image: ImageType, maskImage: ImageData, maskOpacity?: number, maskBlurAmount?: number, flipHorizontal?: boolean, pixelCellWidth?: number): Promise; /** * Given a segmentation or array of segmentations, and an image, draws the image * with its background blurred onto the canvas. * * @param canvas The canvas to draw the background-blurred image onto. * * @param image The image to blur the background of and draw. * * @param segmentation Single segmentation or array of segmentations. * * @param foregroundThreshold Default to 0.5. The minimum probability * to color a pixel as foreground rather than background. The alpha channel * integer values will be taken as the probabilities (for more information refer * to `Segmentation` type's documentation). * * @param backgroundBlurAmount How many pixels in the background blend into each * other. Defaults to 3. Should be an integer between 1 and 20. * * @param edgeBlurAmount How many pixels to blur on the edge between the person * and the background by. Defaults to 3. Should be an integer between 0 and 20. * * @param flipHorizontal If the output should be flipped horizontally. Defaults * to false. */ export declare function drawBokehEffect(canvas: Canvas, image: ImageType, segmentation: Segmentation | Segmentation[], foregroundThreshold?: number, backgroundBlurAmount?: number, edgeBlurAmount?: number, flipHorizontal?: boolean): Promise; /** * Given a personSegmentation and an image, draws the image with its background * blurred onto the canvas. * * @param canvas The canvas to draw the background-blurred image onto. * * @param image The image to blur the background of and draw. * * @param segmentation Single segmentation or array of segmentations. * * @param maskValuesToBlur An array of red channel mask values to blur * (representing different body parts, refer to `Segmentation` interface * docs for more details). * * @param foregroundThreshold Default to 0.5. The minimum probability * to color a pixel as foreground rather than background. The alpha channel * integer values will be taken as the probabilities (for more information refer * to `Segmentation` type's documentation). * * @param backgroundBlurAmount How many pixels in the background blend into each * other. Defaults to 3. Should be an integer between 1 and 20. * * @param edgeBlurAmount How many pixels to blur on the edge between the person * and the background by. Defaults to 3. Should be an integer between 0 and 20. * * @param flipHorizontal If the output should be flipped horizontally. Defaults * to false. */ export declare function blurBodyPart(canvas: Canvas, image: ImageType, segmentation: Segmentation | Segmentation[], maskValuesToBlur: number[], foregroundThreshold?: number, backgroundBlurAmount?: number, edgeBlurAmount?: number, flipHorizontal?: boolean): Promise; export {};