ImageHelper<T>

Helpers & Utilities · AiDotNet.Helpers

Helper class for loading and saving images as tensors.

For Beginners

This class converts image files into tensors for neural networks. Images are loaded as [channels, height, width] or [batch, channels, height, width] tensors.

How It Works

Reads BMP (uncompressed), PPM/PGM and RAW (with explicit dimensions) itself, and PNG, JPEG, GIF, TGA, PSD and HDR through StbImageSharp on every target framework. TIFF and WebP are not supported.

Methods

Method Summary
Tensor<T> LoadBmp(string filePath, bool normalize) Loads a BMP (Windows Bitmap) image file.
Tensor<T> LoadImage(string filePath, bool normalize) Loads an image from a file path and returns it as a tensor.
Tensor<T> LoadPgm(string filePath, bool normalize) Loads a PGM (Portable Graymap) image file.
Tensor<T> LoadPpm(string filePath, bool normalize) Loads a PPM (Portable Pixmap) image file.
Tensor<T> LoadRaw(string filePath, int width, int height, int channels, int bytesPerChannel, bool normalize) Loads raw pixel data from a file.
void SaveBmp(Tensor<T> tensor, string filePath, bool denormalize) Saves a tensor as a BMP image file.
void SavePpm(Tensor<T> tensor, string filePath, bool denormalize, bool binary) Saves a tensor as a PPM image file.