Img2Num C
API Documentation
Loading...
Searching...
No Matches
cimg2num.cpp
Go to the documentation of this file.
1#include "cimg2num.h"
2
3#include <cstring>
4
5#include "img2num.h"
6#include "img2num/Error.h"
7
8extern "C" {
9
10void img2num_gaussian_blur_fft(uint8_t *image, size_t width, size_t height, double sigma) {
11 img2num::clear_last_error_and_catch(img2num::gaussian_blur_fft, image, width, height, sigma);
12}
13
14void img2num_invert_image(uint8_t *image, int width, int height) {
15 img2num::clear_last_error_and_catch(img2num::invert_image, image, width, height);
16}
17
18void img2num_threshold_image(uint8_t *ptr, const int width, const int height,
19 const int num_thresholds) {
20 img2num::clear_last_error_and_catch(img2num::threshold_image, ptr, width, height,
21 num_thresholds);
22}
23
24void img2num_black_threshold_image(uint8_t *ptr, const int width, const int height,
25 const int num_thresholds) {
26 img2num::clear_last_error_and_catch(img2num::black_threshold_image, ptr, width, height,
27 num_thresholds);
28}
29
30void img2num_kmeans(const uint8_t *data, uint8_t *out_data, int32_t *out_labels,
31 const int32_t width, const int32_t height, const int32_t k,
32 const int32_t max_iter, const uint8_t color_space) {
33 img2num::clear_last_error_and_catch(img2num::kmeans, data, out_data, out_labels, width, height,
34 k, max_iter, color_space);
35}
36
37void img2num_bilateral_filter(uint8_t *image, size_t width, size_t height, double sigma_spatial,
38 double sigma_range, uint8_t color_space) {
39 img2num::clear_last_error_and_catch(img2num::bilateral_filter, image, width, height,
40 sigma_spatial, sigma_range, color_space);
41}
42
43char *img2num_labels_to_svg(const uint8_t *data, const int32_t *labels, const int width,
44 const int height, const int min_area) {
45 char *result{nullptr};
46 img2num::clear_last_error_and_catch(
47 [&](const uint8_t *d, const int32_t *l, const int w, const int h, const int min_a) {
48 std::string svg{img2num::labels_to_svg(d, l, w, h, min_a)};
49 result = static_cast<char *>(std::malloc(svg.size() + 1));
50 if (!result) {
51 return; // Allocation failed
52 }
53 std::memcpy(result, svg.c_str(), svg.size() + 1);
54 },
55 data, labels, width, height, min_area);
56 return result;
57}
58}
char * img2num_labels_to_svg(const uint8_t *data, const int32_t *labels, const int width, const int height, const int min_area)
Convert labeled regions of an image into an SVG string.
Definition cimg2num.cpp:43
void img2num_threshold_image(uint8_t *ptr, const int width, const int height, const int num_thresholds)
Apply a thresholding operation to an image.
Definition cimg2num.cpp:18
void img2num_invert_image(uint8_t *image, int width, int height)
Invert the pixel values of an image.
Definition cimg2num.cpp:14
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.
Definition cimg2num.cpp:10
void img2num_black_threshold_image(uint8_t *ptr, const int width, const int height, const int num_thresholds)
Apply black-thresholding to an image.
Definition cimg2num.cpp:24
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.
Definition cimg2num.cpp:30
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.
Definition cimg2num.cpp:37
Core image processing functions for img2num project.