4#include "img2num/Error.h"
11 img2num::ImageToSvgConfig cfg {};
30 cfg.bilateral_filter.sigma_range = cpp.bilateral_filter.sigma_range;
32 cfg.kmeans.k = cpp.kmeans.k;
33 cfg.kmeans.max_iter = cpp.kmeans.max_iter;
35 cfg.min_cluster_area = cpp.min_cluster_area;
36 cfg.min_thickness = cpp.min_thickness;
37 cfg.color_space = cpp.color_space;
44 return to_c(img2num::ImageToSvgConfig {});
48 img2num::clear_last_error_and_catch(img2num::gaussian_blur_fft, image, width, height, sigma);
52 img2num::clear_last_error_and_catch(img2num::invert_image, image, width, height);
56 uint8_t* ptr,
const int width,
const int height,
const int num_thresholds
58 img2num::clear_last_error_and_catch(
59 img2num::threshold_image, ptr, width, height, num_thresholds
64 uint8_t* ptr,
const int width,
const int height,
const int num_thresholds
66 img2num::clear_last_error_and_catch(
67 img2num::black_threshold_image, ptr, width, height, num_thresholds
72 const uint8_t* data, uint8_t* out_data, int32_t* out_labels,
const int32_t width,
73 const int32_t height,
const int32_t k,
const int32_t max_iter,
const uint8_t color_space
75 img2num::clear_last_error_and_catch(
76 img2num::kmeans, data, out_data, out_labels, width, height, k, max_iter, color_space
81 uint8_t* image,
size_t width,
size_t height,
double sigma_spatial,
double sigma_range,
84 img2num::clear_last_error_and_catch(
85 img2num::bilateral_filter, image, width, height, sigma_spatial, sigma_range, color_space
90 const uint8_t* data,
const int32_t* labels,
const int width,
const int height,
91 const int min_area,
const int min_thickness
93 char* result {
nullptr};
94 img2num::clear_last_error_and_catch(
95 [&](
const uint8_t* d,
const int32_t* l,
const int w,
const int h,
const int min_a,
97 std::string svg {img2num::labels_to_svg(d, l, w, h, min_a, min_t)};
98 result =
static_cast<char*
>(std::malloc(svg.size() + 1));
102 std::memcpy(result, svg.c_str(), svg.size() + 1);
104 data, labels, width, height, min_area, min_thickness
116 char* result {
nullptr};
118 img2num::clear_last_error_and_catch(
119 [&](
const uint8_t* d,
const int w,
const int h) {
120 std::string svg {img2num::image_to_svg(d, w, h, to_cpp(cfg))};
122 result =
static_cast<char*
>(std::malloc(svg.size() + 1));
126 std::memcpy(result, svg.c_str(), svg.size() + 1);
char * img2num_image_to_svg(const uint8_t *data, const int width, const int height, const img2num_ImageToSvgConfig *config)
Convert labeled regions of an image into an SVG string.
char * img2num_labels_to_svg(const uint8_t *data, const int32_t *labels, const int width, const int height, const int min_area, const int min_thickness)
Convert labeled regions of an image into an SVG string.
void img2num_threshold_image(uint8_t *ptr, const int width, const int height, const int num_thresholds)
Apply a thresholding operation to an image.
img2num_ImageToSvgConfig img2num_ImageToSvgConfig_default(void)
void img2num_invert_image(uint8_t *image, int width, int height)
Invert the pixel values of an image.
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.
void img2num_black_threshold_image(uint8_t *ptr, const int width, const int height, const int num_thresholds)
Apply black-thresholding to an image.
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.
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.
Core image processing functions for img2num project.
Configuration options for image_to_svg.
int min_thickness
Minimum thickness (in pixels) for a region to be included in the SVG.
int min_cluster_area
Minimum area (in pixels) for a region to be included in the SVG.
struct img2num_ImageToSvgConfig::KMeansConfig kmeans
struct img2num_ImageToSvgConfig::BilateralFilterConfig bilateral_filter