function fromPixels_(pixels, numChannels = 3) {
    // Sanity checks.
    if (numChannels > 4) throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");
    if (pixels == null) throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
    let isPixelData = false;
    let isImageData = false;
    let isVideo = false;
    let isImage = false;
    let isCanvasLike = false;
    let isImageBitmap = false;
    if (pixels.data instanceof Uint8Array) isPixelData = true;
    else if (typeof ImageData !== "undefined" && pixels instanceof ImageData) isImageData = true;
    else if (typeof HTMLVideoElement !== "undefined" && pixels instanceof HTMLVideoElement) isVideo = true;
    else if (typeof HTMLImageElement !== "undefined" && pixels instanceof HTMLImageElement) isImage = true;
    else if (pixels.getContext != null) isCanvasLike = true;
    else if (typeof ImageBitmap !== "undefined" && pixels instanceof ImageBitmap) isImageBitmap = true;
    else throw new Error("pixels passed to tf.browser.fromPixels() must be either an " + `HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData ` + `in browser, or OffscreenCanvas, ImageData in webworker` + ` or {data: Uint32Array, width: number, height: number}, ` + `but was ${pixels.constructor.name}`);
    // If the current backend has 'FromPixels' registered, it has a more
    // efficient way of handling pixel uploads, so we call that.
    const kernel = (0, _kernelRegistry.getKernel)((0, _kernelNames.FromPixels), (0, _engine.ENGINE).backendName);
    if (kernel != null) {
        const inputs = {
            pixels
        };
        const attrs = {
            numChannels
        };
        return (0, _engine.ENGINE).runKernel((0, _kernelNames.FromPixels), inputs, attrs);
    }
    const [width, height] = isVideo ? [
        pixels.videoWidth,
        pixels.videoHeight
    ] : [
        pixels.width,
        pixels.height
    ];
    let vals;
    if (isCanvasLike) vals = // tslint:disable-next-line:no-any
    pixels.getContext("2d").getImageData(0, 0, width, height).data;
    else if (isImageData || isPixelData) vals = pixels.data;
    else if (isImage || isVideo || isImageBitmap) {
        if (fromPixels2DContext == null) {
            if (typeof document === "undefined") {
                if (typeof OffscreenCanvas !== "undefined" && typeof OffscreenCanvasRenderingContext2D !== "undefined") // @ts-ignore
                fromPixels2DContext = new OffscreenCanvas(1, 1).getContext("2d");
                else throw new Error("Cannot parse input in current context. Reason: OffscreenCanvas Context2D rendering is not supported.");
            } else fromPixels2DContext = document.createElement("canvas").getContext("2d", {
                willReadFrequently: true
            });
        }
        fromPixels2DContext.canvas.width = width;
        fromPixels2DContext.canvas.height = height;
        fromPixels2DContext.drawImage(pixels, 0, 0, width, height);
        vals = fromPixels2DContext.getImageData(0, 0, width, height).data;
    }
    let values;
    if (numChannels === 4) values = new Int32Array(vals);
    else {
        const numPixels = width * height;
        values = new Int32Array(numPixels * numChannels);
        for(let i = 0; i < numPixels; i++)for(let channel = 0; channel < numChannels; ++channel)values[i * numChannels + channel] = vals[i * 4 + channel];
    }
    const outShape = [
        height,
        width,
        numChannels
    ];
    return (0, _tensor3D.tensor3d)(values, outShape, "int32");
}
Creates a `tf.Tensor` from an image.

```js
const image = new ImageData(1, 1);
image.data[0] = 100;
image.data[1] = 150;
image.data[2] = 200;
image.data[3] = 255;

tf.browser.fromPixels(image).print();
```

@param pixels The input image to construct the tensor from. The
supported image types are all 4-channel. You can also pass in an image
object with following attributes:
`{data: Uint8Array; width: number; height: number}`
@param numChannels The number of channels of the output tensor. A
numChannels value less than 4 allows you to ignore channels. Defaults to
3 (ignores alpha channel of input image).

@returns A Tensor3D with the shape `[height, width, numChannels]`.

Note: fromPixels can be lossy in some cases, same image may result in
slightly different tensor values, if rendered by different rendering
engines. This means that results from different browsers, or even same
browser with CPU and GPU rendering engines can be different. See discussion
in details:
https://github.com/tensorflow/tfjs/issues/5482

@doc {heading: 'Browser', namespace: 'browser', ignoreCI: true}