Img2Num C
API Documentation
cimg2num.h File Reference

Core image processing functions for img2num project. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+ Include dependency graph for cimg2num.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void img2num_gaussian_blur_fft (uint8_t *image, size_t width, size_t height, double sigma)
 Apply a Gaussian blur to an image using FFT. More...
 
void img2num_invert_image (uint8_t *ptr, int width, int height)
 Invert the pixel values of an image. More...
 
void img2num_threshold_image (uint8_t *ptr, const int width, const int height, const int num_thresholds)
 Apply a thresholding operation to an image. More...
 
void img2num_black_threshold_image (uint8_t *ptr, const int width, const int height, const int num_thresholds)
 Apply black-thresholding to an image. More...
 
void img2num_kmeans (const uint8_t *data, uint8_t *out_data, int32_t *out_labels, const int32_t width, const int32_t height, const int32_t k, const int32_t max_iter, const uint8_t color_space)
 Perform k-means clustering on image data. More...
 
void img2num_bilateral_filter (uint8_t *image, size_t width, size_t height, double sigma_spatial, double sigma_range, uint8_t color_space)
 Apply bilateral filtering to an image. More...
 
char * img2num_labels_to_svg (uint8_t *data, int32_t *labels, const int width, const int height, const int min_area, const bool draw_contour_borders)
 Convert labeled regions of an image into an SVG string. More...
 

Detailed Description

Core image processing functions for img2num project.

This file declares functions for image manipulation, clustering, filtering, and conversion to SVG. Functions operate on raw image buffers (uint8_t*).

Definition in file cimg2num.h.

Function Documentation

◆ img2num_bilateral_filter()

void img2num_bilateral_filter ( uint8_t *  image,
size_t  width,
size_t  height,
double  sigma_spatial,
double  sigma_range,
uint8_t  color_space 
)

Apply bilateral filtering to an image.

Parameters
imagePointer to RGBA pixel buffer.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
sigma_spatialStandard deviation for spatial Gaussian (proximity weight).
sigma_rangeStandard deviation for range Gaussian (intensity similarity weight).
color_spaceColor space flag (0 = CIE LAB, 1 = RGB).
Note
The filter modifies the image buffer in-place.
Dox File: doxygen/img2num.h.dox

Definition at line 35 of file cimg2num.cpp.

36  {
37  img2num::clear_last_error_and_catch(img2num::bilateral_filter, image, width, height,
38  sigma_spatial, sigma_range, color_space);
39 }

◆ img2num_black_threshold_image()

void img2num_black_threshold_image ( uint8_t *  ptr,
const int  width,
const int  height,
const int  num_thresholds 
)

Apply black-thresholding to an image.

Parameters
ptrPointer to the image buffer.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
num_thresholdsNumber of thresholds to apply.
Note
Similar to threshold_image but prioritizes darker pixels.
Dox File: doxygen/img2num.h.dox

Definition at line 22 of file cimg2num.cpp.

23  {
24  img2num::clear_last_error_and_catch(img2num::black_threshold_image, ptr, width, height,
25  num_thresholds);
26 }

◆ img2num_gaussian_blur_fft()

void img2num_gaussian_blur_fft ( uint8_t *  image,
size_t  width,
size_t  height,
double  sigma 
)

Apply a Gaussian blur to an image using FFT.

Parameters
imagePointer to the image buffer (RGBA).
widthWidth of the image in pixels.
heightHeight of the image in pixels.
sigmaStandard deviation for Gaussian kernel.
Note
The operation modifies the image buffer in-place.
Dox File: doxygen/img2num.h.dox

Definition at line 8 of file cimg2num.cpp.

8  {
9  img2num::clear_last_error_and_catch(img2num::gaussian_blur_fft, image, width, height, sigma);
10 }

◆ img2num_invert_image()

void img2num_invert_image ( uint8_t *  ptr,
int  width,
int  height 
)

Invert the pixel values of an image.

Parameters
ptrPointer to the image buffer.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
Note
Each pixel value is replaced by 255 - original_value.
Dox File: doxygen/img2num.h.dox

Definition at line 12 of file cimg2num.cpp.

12  {
13  img2num::clear_last_error_and_catch(img2num::invert_image, image, width, height);
14 }

◆ img2num_kmeans()

void img2num_kmeans ( const uint8_t *  data,
uint8_t *  out_data,
int32_t *  out_labels,
const int32_t  width,
const int32_t  height,
const int32_t  k,
const int32_t  max_iter,
const uint8_t  color_space 
)

Perform k-means clustering on image data.

Parameters
dataPointer to input image data buffer.
out_dataPointer to output buffer where clustered pixel values are stored.
out_labelsPointer to output buffer for cluster labels per pixel.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
kNumber of clusters to compute.
max_iterMaximum number of iterations for the algorithm.
color_spaceColor space flag (0 = CIE LAB, 1 = RGB).
Note
The function does not modify the input buffer.
Dox File: doxygen/img2num.h.dox

Definition at line 28 of file cimg2num.cpp.

30  {
31  img2num::clear_last_error_and_catch(img2num::kmeans, data, out_data, out_labels, width, height,
32  k, max_iter, color_space);
33 }

◆ img2num_labels_to_svg()

char* img2num_labels_to_svg ( uint8_t *  data,
int32_t *  labels,
const int  width,
const int  height,
const int  min_area,
const bool  draw_contour_borders 
)

Convert labeled regions of an image into an SVG string.

Parameters
dataPointer to image data buffer.
labelsPointer to label buffer, indicating region for each pixel.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
min_areaMinimum area (in pixels) for a region to be included in the SVG.
draw_contour_bordersIf true, contours of labeled regions will be drawn.
Returns
Pointer to a dynamically allocated C-string containing the SVG data.
Note
Caller is responsible for freeing the returned string.
Dox File: doxygen/img2num.h.dox

Definition at line 41 of file cimg2num.cpp.

42  {
43  char *result{nullptr};
44  img2num::clear_last_error_and_catch(
45  [&](uint8_t *d, int32_t *l, int w, int h, int min_a, bool draw_contours) {
46  result = img2num::labels_to_svg(d, l, w, h, min_a, draw_contours);
47  },
48  data, labels, width, height, min_area, draw_contour_borders);
49  return result;
50 }

◆ img2num_threshold_image()

void img2num_threshold_image ( uint8_t *  ptr,
const int  width,
const int  height,
const int  num_thresholds 
)

Apply a thresholding operation to an image.

Parameters
ptrPointer to the image buffer.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
num_thresholdsNumber of thresholds to apply.
Note
Thresholds split pixel intensity ranges into discrete levels.
Dox File: doxygen/img2num.h.dox

Definition at line 16 of file cimg2num.cpp.

17  {
18  img2num::clear_last_error_and_catch(img2num::threshold_image, ptr, width, height,
19  num_thresholds);
20 }