Helper module for image processing.
These functions and classes are only used internally, meaning an end-user shouldn’t need to access anything here.
new RawImage(data, width, height, channels).size ⇒ *.grayscale() ⇒ RawImage.rgb() ⇒ RawImage.rgba() ⇒ RawImage.resize(width, height, options) ⇒ Promise.<RawImage>.clone() ⇒ RawImage.convert(numChannels) ⇒ RawImage.save(path).read(input) ⇒ *.fromCanvas(canvas) ⇒ RawImage.fromURL(url) ⇒ Promise.<RawImage>.fromBlob(blob) ⇒ Promise.<RawImage>.fromTensor(tensor)Kind: static class of utils/image
new RawImage(data, width, height, channels).size ⇒ *.grayscale() ⇒ RawImage.rgb() ⇒ RawImage.rgba() ⇒ RawImage.resize(width, height, options) ⇒ Promise.<RawImage>.clone() ⇒ RawImage.convert(numChannels) ⇒ RawImage.save(path).read(input) ⇒ *.fromCanvas(canvas) ⇒ RawImage.fromURL(url) ⇒ Promise.<RawImage>.fromBlob(blob) ⇒ Promise.<RawImage>.fromTensor(tensor)Create a new RawImage object.
| Param | Type | Description |
|---|---|---|
| data | Uint8ClampedArray | Uint8Array | The pixel data. |
| width | number | The width of the image. |
| height | number | The height of the image. |
| channels | 1 | 2 | 3 | 4 | The number of channels. |
Returns the size of the image (width, height).
Kind: instance property of RawImage
Returns: * - The size of the image (width, height).
Convert the image to grayscale format.
Kind: instance method of RawImage
Returns: RawImage - this to support chaining.
Convert the image to RGB format.
Kind: instance method of RawImage
Returns: RawImage - this to support chaining.
Convert the image to RGBA format.
Kind: instance method of RawImage
Returns: RawImage - this to support chaining.
Resize the image to the given dimensions. This method uses the canvas API to perform the resizing.
Kind: instance method of RawImage
Returns: Promise.<RawImage> - this to support chaining.
| Param | Type | Description |
|---|---|---|
| width | number | The width of the new image. |
| height | number | The height of the new image. |
| options | Object | Additional options for resizing. |
| [options.resample] | 0 | 1 | 2 | 3 | 4 | 5 | string | The resampling method to use. |
Clone the image
Kind: instance method of RawImage
Returns: RawImage - The cloned image
Helper method for converting image to have a certain number of channels
Kind: instance method of RawImage
Returns: RawImage - this to support chaining.
| Param | Type | Description |
|---|---|---|
| numChannels | number | The number of channels. Must be 1, 3, or 4. |
Save the image to the given path.
Kind: instance method of RawImage
| Param | Type | Description |
|---|---|---|
| path | string | The path to save the image to. |
Helper method for reading an image from a variety of input types.
Kind: static method of RawImage
Returns: * - The image object.
Example: Read image from a URL.
let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
// RawImage | Param | Type |
|---|---|
| input | RawImage | string | URL |
Read an image from a canvas.
Kind: static method of RawImage
Returns: RawImage - The image object.
| Param | Type | Description |
|---|---|---|
| canvas | HTMLCanvasElement | OffscreenCanvas | The canvas to read the image from. |
Read an image from a URL or file path.
Kind: static method of RawImage
Returns: Promise.<RawImage> - The image object.
| Param | Type | Description |
|---|---|---|
| url | string | URL | The URL or file path to read the image from. |
Helper method to create a new Image from a blob.
Kind: static method of RawImage
Returns: Promise.<RawImage> - The image object.
| Param | Type | Description |
|---|---|---|
| blob | Blob | The blob to read the image from. |
Helper method to create a new Image from a tensor
Kind: static method of RawImage
| Param | Type |
|---|---|
| tensor | Tensor |
Mapping from file extensions to MIME types.
Kind: inner constant of utils/image