|
OCR Project
|
Image preprocessing pipeline using libpng (no SDL2_image required). More...
#include "image.h"#include <math.h>#include <png.h>#include <stdio.h>#include <stdlib.h>#include <string.h>
Functions | |
| static Image * | image_alloc (int w, int h) |
| Allocate an Image of given dimensions with a zeroed pixel buffer. | |
| void | image_free (Image *img) |
| Free an Image allocated by image_load_png(). | |
| Image * | image_load_png (const char *path) |
| Load a PNG file into an Image. | |
| int | image_save_png (const Image *img, const char *path) |
| Save an Image as a PNG file. | |
| void | image_to_grayscale (Image *img) |
| Convert an Image to grayscale in-place. | |
| void | image_binarize (Image *img) |
| Binarise a grayscale Image in-place using a global threshold. | |
| Image * | image_resize (const Image *src, int w, int h) |
| Resize an Image to the given dimensions (nearest-neighbour). | |
| Image * | image_rotate (const Image *src, float angle_deg) |
Rotate an Image by angle_deg degrees clockwise. | |
| void | image_to_float (const Image *img, float *out) |
| Convert an Image to a flat normalised float array. | |
| int | image_load_normalised (const char *path, const PreprocessParams *p, float *out, int out_h, int out_w) |
| Full pipeline: load PNG → preprocess → resize → float array. | |
Image preprocessing pipeline using libpng (no SDL2_image required).
|
static |
| void image_binarize | ( | Image * | img | ) |
Binarise a grayscale Image in-place using a global threshold.
The threshold is the mean pixel luminance of the image. Pixels above the threshold → 255 (white/background). Pixels at or below → 0 (black/ink).
| img | Grayscale Image (R channel used as luminance). |

| void image_free | ( | Image * | img | ) |
Free an Image allocated by image_load_png().
| img | Image to free. No-op if NULL. |

| int image_load_normalised | ( | const char * | path, |
| const PreprocessParams * | p, | ||
| float * | out, | ||
| int | out_h, | ||
| int | out_w ) |
Full pipeline: load PNG → preprocess → resize → float array.
| path | Path to the source PNG file. |
| p | Preprocessing parameters (may be NULL for defaults). |
| out | Output buffer of size out_h * out_w floats. |
| out_h | Target height (e.g. 28 for CNN input). |
| out_w | Target width (e.g. 28 for CNN input). |


| Image * image_load_png | ( | const char * | path | ) |
Load a PNG file into an Image.
| path | Path to the PNG file. |


Resize an Image to the given dimensions (nearest-neighbour).
Returns a new Image; the original is not modified.
| img | Source Image. |
| w | Target width in pixels. |
| h | Target height in pixels. |


Rotate an Image by angle_deg degrees clockwise.
Returns a new Image large enough to contain the full rotated content. Background pixels are set to white (255, 255, 255, 255).
| img | Source Image. |
| angle_deg | Rotation angle in degrees (clockwise). |


| int image_save_png | ( | const Image * | img, |
| const char * | path ) |
| void image_to_float | ( | const Image * | img, |
| float * | out ) |
Convert an Image to a flat normalised float array.
Reads the R channel (expected to hold grayscale luminance). Ink (R=0) → 1.0f, background (R=255) → 0.0f.
| img | Source Image (must be grayscale). |
| out | Output buffer of size img->width * img->height floats. |
