ImageTensor<T>
Models & Types · AiDotNet.Augmentation.Image
Represents an image as a tensor with image-specific metadata and operations.
For Beginners
An image on a computer is stored as numbers representing pixel colors. This class represents those numbers in a way that’s optimized for machine learning, while keeping track of important details like whether the image is in RGB or BGR format.
How It Works
ImageTensor wraps a Tensor
- Channel ordering (CHW vs HWC)
- Color space awareness (RGB, BGR, HSV, etc.)
- Normalization state tracking
- Image-specific operations (crop, resize, color conversion)
Constructors
| Constructor | Summary |
|---|---|
ImageTensor(Tensor<T> data, ChannelOrder channelOrder, ColorSpace colorSpace) |
Creates an ImageTensor from an existing tensor. |
ImageTensor(int batchSize, int height, int width, int channels, ChannelOrder channelOrder, ColorSpace colorSpace) |
Creates a batched ImageTensor with specified dimensions. |
ImageTensor(int height, int width, int channels, ChannelOrder channelOrder, ColorSpace colorSpace) |
Creates an ImageTensor with specified dimensions. |
Properties
| Property | Summary |
|---|---|
ChannelOrder ChannelOrder { get; set; } |
Gets or sets the channel ordering. |
ColorSpace ColorSpace { get; set; } |
Gets or sets the color space. |
IDictionary<string, object> Metadata { get; set; } |
Gets or sets additional metadata. |
T[] NormalizationMean { get; set; } |
Gets or sets the normalization mean (per channel). |
T[] NormalizationStd { get; set; } |
Gets or sets the normalization std (per channel). |
Tensor<T> Data { get; } |
Gets the underlying tensor data. |
ValueTuple<T, T>? OriginalRange { get; set; } |
Gets or sets the original value range before normalization. |
bool IsNormalized { get; set; } |
Gets or sets whether the image is normalized to [0, 1]. |
int BatchSize { get; set; } |
Gets the batch size (1 for single images). |
int Channels { get; set; } |
Gets the number of channels. |
int Height { get; set; } |
Gets the image height in pixels. |
int Width { get; set; } |
Gets the image width in pixels. |
Methods
| Method | Summary |
|---|---|
ImageTensor<T> Clone() |
Creates a deep copy of this image tensor. |
ImageTensor<T> Crop(int x, int y, int width, int height) |
Extracts a rectangular region from the image. |
ImageTensor<T> ToChannelOrder(ChannelOrder targetOrder) |
Converts this image to a different channel order. |
T GetPixel(int y, int x, int channel) |
Gets a pixel value at the specified coordinates. |
T[] GetPixelChannels(int y, int x) |
Gets all channel values at a pixel location. |
int[] GetDimensions() |
Gets the tensor dimensions as an array. |
void SetPixel(int y, int x, int channel, T value) |
Sets a pixel value at the specified coordinates. |
void SetPixelChannels(int y, int x, T[] values) |
Sets all channel values at a pixel location. |