UtilsImage
-
namespace utilsimages
Functions
-
static inline vector<vector<double>> read_images(string full_path, int num_images, int img_size)
Read CIFAR-10 image data and return multiple images as normalized vectors.
- Parameters:
full_path – Path to binary file.
num_images – Number of images to read.
img_size – Size of one image (in bytes).
- Returns:
Vector of images, each image stored as a flattened [R,G,B] channel vector.
-
static inline void display_image(vector<double> allPixels, int imageSize, bool pixelState)
Display pixel values of a single image in channel-wise 32x32 format.
- Parameters:
allPixels – Flattened vector of one image (3 * 32 * 32).
imageSize – Size of image vector.
pixelState – If true, prints pixel values channel by channel.
-
static inline void clear_images(vector<vector<double>> imagesData, int numImages)
Clear image data from memory.
- Parameters:
imagesData – Vector of images.
numImages – Number of images (unused, kept for consistency).
-
static inline unsigned char **read_mnist_images(string full_path, int &number_of_images, int &image_size)
Read MNIST images from a binary file into a 2D unsigned char array.
- Parameters:
full_path – Path to MNIST image file (e.g., train-images.idx3-ubyte).
number_of_images – Output parameter: number of images read.
image_size – Output parameter: number of pixels per image (rows × cols).
- Throws:
runtime_error – If file cannot be opened or is invalid.
- Returns:
Pointer to 2D array of image data [num_images][image_size].
-
static inline vector<double> read_single_mnist_image(unsigned char *imageData, int imageSize)
Convert a single MNIST image to a normalized vector of doubles.
Normalization: (pixel / 255.0 - mean) / std. Uses mean = 0.1307, std = 0.3081.
- Parameters:
imageData – Pointer to raw image data (unsigned char array).
imageSize – Number of pixels (28 × 28).
- Returns:
Normalized image as a vector<double>.
-
static inline vector<double> read_multi_mnist_images(unsigned char *imageData, int batchSize, int imageSize)
Read and normalize multiple MNIST images into a single batched vector.
Takes raw unsigned char pixel data for multiple MNIST images, normalizes each pixel value using the dataset’s mean and standard deviation, and concatenates all images into one flattened vector.
- Parameters:
imageData – Pointer to the raw pixel data (batchSize * imageSize bytes).
batchSize – Number of images in the batch.
imageSize – Number of pixels per image (e.g., 28*28 for MNIST).
- Returns:
Flattened vector<double> of size batchSize * imageSize containing all normalized images in order: [batch0 image][batch1 image]…
-
static inline void display_mnist_image(unsigned char *imageData, int imageSize, bool pixelState)
Display a single MNIST image in 28×28 format.
- Parameters:
imageData – Pointer to raw image data (unsigned char array).
imageSize – Number of pixels (28 × 28).
pixelState – If true, prints pixel intensity values. If false, prints ASCII visualization (“X” or “.”).
-
static inline void clear_mnist_images(unsigned char **mnistData, int numImages)
Free memory allocated for MNIST image dataset.
- Parameters:
mnistData – Pointer to 2D array of MNIST images.
numImages – Number of images to free.
-
static inline vector<vector<double>> read_images(string full_path, int num_images, int img_size)