Documentation
¶
Overview ¶
Package image provides several functions to transform images back and forth from tensors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ToImageConfig ¶
type ToImageConfig struct {
// contains filtered or unexported fields
}
ToImageConfig holds the configuration returned by the ToImage function. Once configured, use Single or Batch to actually convert a tensor to image(s).
func ToImage ¶
func ToImage() *ToImageConfig
ToImage returns a configuration that can be used to convert tensors to Images. Use Single or Batch to convert single images or batch of images at once.
For now, it only supports `*image.NRGBA` image type.
func (*ToImageConfig) Batch ¶
func (ti *ToImageConfig) Batch(t tensor.Tensor) []image.Image
Batch converts the given 4D tensor shaped as `[batch_size, height, width, channels]` to a collection of images to a tensor, using the ToImageConfig.
func (*ToImageConfig) MaxValue ¶
func (ti *ToImageConfig) MaxValue(v float64) *ToImageConfig
MaxValue sets the MaxValue of each channel. It defaults to 1.0 for float dtypes (Float32 and Float64) and 255 for integer types.
Notice while this value is given as float64, it is converted to the corresponding dtype.
It returns the ToImageConfig object, so configuration calls can be cascaded.
type ToTensorConfig ¶
type ToTensorConfig struct {
// contains filtered or unexported fields
}
ToTensorConfig holds the configuration returned by the ToTensor function. Once configured, use Single or Batch to actually convert.
func ToTensor ¶
func ToTensor(dtype shapes.DType) *ToTensorConfig
ToTensor converts an image (or batch) a tensor.Local.
It returns a configuration object that can be further configured. Once set, use Single or Batch methods to convert an image or a batch of images.
func (*ToTensorConfig) Batch ¶
func (tt *ToTensorConfig) Batch(images []image.Image) (t *tensor.Local)
Batch converts the given images to a tensor, using the ToTensorConfig.
It returns a 4D tensor, shaped as `[batch_size, height, width, channels]`.
func (*ToTensorConfig) MaxValue ¶
func (tt *ToTensorConfig) MaxValue(v float64) *ToTensorConfig
MaxValue sets the MaxValue of each channel. It defaults to 1.0 for float dtypes (Float32 and Float64) and 255 for integer types.
Notice while this value is given as float64, it is converted to the corresponding dtype.
It returns the ToTensorConfig object, so configuration calls can be cascaded.
func (*ToTensorConfig) Single ¶
func (tt *ToTensorConfig) Single(img image.Image) (t *tensor.Local)
Single converts the given img to a tensor, using the ToTensorConfig.
It returns a 3D tensor, shaped as `[height, width, channels]`.
func (*ToTensorConfig) WithAlpha ¶
func (tt *ToTensorConfig) WithAlpha() *ToTensorConfig
WithAlpha configures ToTensorConfig object to include the alpha channel in the conversion, so the converted tensor will have 4 channels. The default is dropping the alpha channel.
It returns the ToTensorConfig object, so configuration calls can be cascaded.