Struct TextureTransform
Represents settings for converting between textures and tensors.
Create an instance of TextureTransform
using the constructor, then use the TextureTransform
object as a parameter in TextureConverter
methods.
For example: TextureTransform settings = new TextureTransform().SetDimensions(256, 256, 4).SetTensorLayout(TensorLayout.NHWC);
Inherited Members
Namespace: Unity.Sentis
Assembly: Unity.Sentis.dll
Syntax
public struct TextureTransform
Methods
SetBroadcastChannels(bool)
Sets the default behaviour when the output texture has more channels than the input tensor.
When broadcastChannels
is true
, Sentis broadcasts the tensor values to additional channels in the render texture. For example, a tensor with a single channel R maps to (R, R, R, R) if the number of channels is 4.
When broadcastChannels
is false
, Sentis applies a (0, 0, 0, 1) color mask to additional channels in the render texture. For example, a tensor with a single channel R becomes (R, 0, 0, 1) if the number of channels is 4.
Declaration
public TextureTransform SetBroadcastChannels(bool broadcastChannels)
Parameters
Type | Name | Description |
---|---|---|
bool | broadcastChannels | Whether to broadcast the input channels across output channels. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetChannelColorMask(bool, bool, bool, bool, Color)
Sets which channels in the output texture ignore input tensor values and write a specific color
instead.
The method returns a TextureTransform
that you can use to chain other methods.
Declaration
public TextureTransform SetChannelColorMask(bool maskR, bool maskG, bool maskB, bool maskA, Color color)
Parameters
Type | Name | Description |
---|---|---|
bool | maskR | The mask value for the red channel. |
bool | maskG | The mask value for the green channel. |
bool | maskB | The mask value for the blue channel. |
bool | maskA | The mask value for the alpha channel. |
Color | color | The color value to use when masking. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetChannelColorMask(Channel, bool, float)
Sets a specific texture channel, for example Channel.R
, to a specific color
. The channel ignores input tensor values.
Declaration
public TextureTransform SetChannelColorMask(Channel c, bool mask, float color)
Parameters
Type | Name | Description |
---|---|---|
Channel | c | The color channel to set. |
bool | mask | When the value is |
float | color | The color value to use. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetChannelSwizzle(int, int, int, int)
Sets which channels in the tensor map to which RGBA channels in the texture, using four channel position values.
A color mask for tensor to texture conversions might override this setting.
Declaration
public TextureTransform SetChannelSwizzle(int channelSwizzleR = 0, int channelSwizzleG = 1, int channelSwizzleB = 2, int channelSwizzleA = 3)
Parameters
Type | Name | Description |
---|---|---|
int | channelSwizzleR | Index in tensor channel axis for red texture channel. |
int | channelSwizzleG | Index in tensor channel axis for green texture channel. |
int | channelSwizzleB | Index in tensor channel axis for blue texture channel. |
int | channelSwizzleA | Index in tensor channel axis for alpha texture channel. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetChannelSwizzle(Channel, int)
Sets a specific texture channel, for example Channel.R
, to a specific position in the tensor.
A color mask for tensor to texture conversions might override this setting.
Declaration
public TextureTransform SetChannelSwizzle(Channel c, int swizzle)
Parameters
Type | Name | Description |
---|---|---|
Channel | c | The color channel to set. |
int | swizzle | The index in the channel tensor axis. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetChannelSwizzle(ChannelSwizzle)
Sets which channels in the tensor map to which RGBA channels in the texture, using a ChannelSwizzle
enum value.
A color mask for tensor to texture conversions might override this setting.
Declaration
public TextureTransform SetChannelSwizzle(ChannelSwizzle channelSwizzle)
Parameters
Type | Name | Description |
---|---|---|
ChannelSwizzle | channelSwizzle | The channel swizzle enum to use. |
Returns
Type | Description |
---|---|
TextureTransform |
|
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if unknown |
SetCoordOrigin(CoordOrigin)
Sets the position of the origin (0, 0) in the tensor.
Declaration
public TextureTransform SetCoordOrigin(CoordOrigin coordOrigin)
Parameters
Type | Name | Description |
---|---|---|
CoordOrigin | coordOrigin | The position of the texture origin in the tensor. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetDimensions(int, int, int)
Sets the dimensions of the output texture or tensor. The default value is -1, which means Sentis infers the dimensions from the input texture or tensor.
If the width and height of the input don't match the width and height of the output, Sentis applies linear resampling.
If you use SetDimensions
in a blit to an existing texture, Sentis ignores width
, height
, and channels
.
The method returns a TextureTransform
that you can use to chain other methods.
Declaration
public TextureTransform SetDimensions(int width = -1, int height = -1, int channels = -1)
Parameters
Type | Name | Description |
---|---|---|
int | width | The width to use for the output. |
int | height | The height to use for the output. |
int | channels | The channel count to use for the output. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetTensorLayout(int, int, int, int)
Sets the layout of the input tensor with four int values.
Declaration
public TextureTransform SetTensorLayout(int tensorLayoutAxisN, int tensorLayoutAxisC, int tensorLayoutAxisH, int tensorLayoutAxisW)
Parameters
Type | Name | Description |
---|---|---|
int | tensorLayoutAxisN | The axis in the tensor for the batch size of the texture. |
int | tensorLayoutAxisC | The axis in the tensor for the channel count of the texture. |
int | tensorLayoutAxisH | The axis in the tensor for the height of the texture. |
int | tensorLayoutAxisW | The axis in the tensor for the width of the texture. |
Returns
Type | Description |
---|---|
TextureTransform |
|
SetTensorLayout(TensorLayout)
Sets the layout of the input tensor with a TensorLayout
object, for example TensorLayout.NHWC
. The default is TensorLayout.NCHW
.
Declaration
public TextureTransform SetTensorLayout(TensorLayout tensorLayout)
Parameters
Type | Name | Description |
---|---|---|
TensorLayout | tensorLayout | Selected tensor layout type. |
Returns
Type | Description |
---|---|
TextureTransform |
|
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if unknown |