Documentation ¶
Overview ¶
Package image provides several functions to transform images back and forth from tensors.
Index ¶
- func GetChannelsAxis(image shapes.HasShape, config ChannelsAxisConfig) int
- func GetSpatialAxes(image shapes.HasShape, config ChannelsAxisConfig) (spatialAxes []int)
- func GetUpSampledSizes(image shapes.HasShape, config ChannelsAxisConfig, factors ...int) (dims []int)
- type ChannelsAxisConfig
- type ToImageConfig
- type ToTensorConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChannelsAxis ¶ added in v0.3.0
func GetChannelsAxis(image shapes.HasShape, config ChannelsAxisConfig) int
GetChannelsAxis from a given image tensor and configuration. It assumes the leading axis is for the batch dimension. So it either returns 1 or `image.Rank()-1`.
func GetSpatialAxes ¶ added in v0.3.0
func GetSpatialAxes(image shapes.HasShape, config ChannelsAxisConfig) (spatialAxes []int)
GetSpatialAxes from a given image tensor and configuration. It assumes the leading axis is for the batch dimension.
Example: if image has shape `[batch_dim, height, width, channels]`, it will return `[]int{1, 2}`.
func GetUpSampledSizes ¶ added in v0.4.0
func GetUpSampledSizes(image shapes.HasShape, config ChannelsAxisConfig, factors ...int) (dims []int)
GetUpSampledSizes returns the dimensions of an image tensor with the spatial dimensions up-sampled by the given factors. If only one factor is given, it is applied to all spatial dimensions.
This can be used to up-sample an image, when combined with interpolation.
Example: To double the size of an image (or video)
img = Interpolate(img, GetUpSampledSizes(img, ChannelsLast, 2)...).Done()
Types ¶
type ChannelsAxisConfig ¶ added in v0.3.0
type ChannelsAxisConfig uint8
ChannelsAxisConfig indicates if a tensor with an image has the channels axis coming last (last axis) or first (first axis after batch axis).
const ( ChannelsFirst ChannelsAxisConfig = iota ChannelsLast )
func (ChannelsAxisConfig) String ¶ added in v0.3.0
func (i ChannelsAxisConfig) String() string
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 ¶
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.