Skip to main content

upscale

Upscales a given image.

Example

const upscaler = new Upscaler();
const image = new Image();
image.src = '/some/path/to/image.png';

upscaler.upscale(image, {
output: 'base64',
patchSize: 64,
padding: 2,
progress: (progress) => {
console.log('Progress:', progress);
},
}).then(upscaledSrc => {
console.log(upscaledSrc);
});
Defined in upscaler.ts:111

Parameters

  • image: Input - The image to upscale.
  • options: - A set of upscaling arguments.
    • signal?: AbortSignal - Provides a mechanism to abort the warmup process. For more, see the guides on cancelling requests.
    • awaitNextFrame?: boolean - If provided, upscaler will await tf.nextFrame() on each cycle. This can be helpful if you need to release for the UI thread or wish to be more responsive to abort signals.
    • output?: base64 | tensor - Denotes the kind of response UpscalerJS returns - a base64 string representation of the image, or the tensor. In the browser, this defaults to "base64" and in Node.js, to "tensor".
    • patchSize?: number - Optionally specify an image patch size to operate on. For more, see the guide on patch sizes.
    • padding?: number - Optionally specify a patch size padding. For more, see the guide on patch sizes.
    • progress?: Progress - An optional progress callback if upscale is called with a patchSize argument. For more, see the guide on progress callbacks.
    • progressOutput?: base64 | tensor - Denotes the kind of response UpscalerJS returns within a progress callback.

Input

  • Browser: tf.Tensor3D | tf.Tensor4D | string | tf.FromPixelsInputs
  • Node: tf.Tensor3D | tf.Tensor4D | string | Uint8Array | Buffer

Progress

The progress callback function has the following four parameters:

  • progress - a number between 0 and 1 representing the progress of the upscale.
  • slice - a string or 3D tensor representing the current slice of the image being processed. The type returned is specified by the progressOutput option, or if not present, the output option, or if not present, string for the browser and tensor for node.
  • row - the row of the image being processed.
  • col - the column of the image being processed.

See the guide on progress for more information.

Returns

Promise<Tensor3D | string> - an upscaled image.