Skip to main content
Version: Next

Interface: Media

torchlive/media.Media

Methods

imageFromBlob

imageFromBlob(blob, width, height): Image

deprecated This function will be removed in the next release. Use imageFromTensor instead.

const tensor = torch.fromBlob(blob, [imageHeight, imageWidth, channels]);
const image = media.imageFromTensor(tensor);

Converts a Blob into an Image. The blob should be in RGB format. The width and height input should match the blob size. i.e. blob.getDirectSize() equals width * height * 3.

Parameters

NameTypeDescription
blobBlobBlob to turn into an Image.
widthnumberThe width of the image.
heightnumber-

Returns

Image

An Image object created from the Blob.


imageFromTensor

imageFromTensor(tensor): Image

Converts a Tensor into an Image. The tensor should be in CHW (channels, height, width) format, with uint8 type.

There are some assumptions made about the input tensor:

  • If the tensor has 4 channels, it is assumed to be RGBA.
  • If the tensor has 3 channels, it is assumed to be RGB.
  • If the tensor has 1 channel, it is assumed to be grayscale.

Parameters

NameTypeDescription
tensorTensorTensor to turn into an Image.

Returns

Image

An Image object created from the Tensor.


toBlob

toBlob(obj): Blob

Converts a Tensor or NativeJSRef into a Blob. The blob can be used to create a Tensor object or convert into a NativeJSRef like an image or audio.

Parameters

NameTypeDescription
objNativeJSRef | TensorObject to turn into a Blob.

Returns

Blob