Module show_image::tch [−][src]
tch
only.Expand description
Support for the tch
crate.
This module adds support for displaying tch::Tensor
as images.
The main interface is provided by an extension trait TensorAsImage
,
which allows you to wrap a tensor in a TensorImage
.
The wrapper struct adds some required meta-data for interpreting the tensor data as an image.
The meta-data has to be supplied by the user, or it can be guessed automatically based on the tensor shape.
When guessing, you do need to specify if you want to interpret multi-channel tensors as RGB or BGR.
An extension trait TensorAsImage
is provided to construct the wrapper with the proper meta-data.
It is not always possible to interpret a tensor as the requested image format,
so all function in the extension trait return a Result
.
The Into<Image>
trait is implemented for TensorImage
and for Result
<
TensorImage
,
ImageDataError
>
,
so you can directly pass use the result to so set the image of a window directly.
Both planar and interlaced tensors are supported. If you specify the format manually, you must also specify if the tensor contains interlaced or planar data. If you let the library guess, it will try to deduce it automatically based on the tensor shape.
Example
use show_image::{create_window, WindowOptions};
use show_image::tch::TensorAsImage;
let tensor = tch::vision::imagenet::load_image("/path/to/image.png").unwrap();
let window = create_window("image", WindowOptions::default())?;
window.set_image("image-001", tensor.as_image_guess_rgb())?;
Structs
Wrapper for tch::Tensor
that implements Into<Image>
.
Enums
A preferred color format for guessing the pixel format of a tensor.
The pixel format of a tensor, or a color format to guess the pixel format.
Traits
Extension trait to allow displaying tensors as image.