Img2Num C++
API Documentation
Loading...
Searching...
No Matches
img2num Namespace Reference

Enumerations

enum class  Error {
  OK = 0 , BAD_ALLOC = 1 , INVALID_ARGUMENT = 2 , RUNTIME = 3 ,
  UNKNOWN = 4
}
 

Functions

Error get_last_error ()
 
const std::string get_last_error_message ()
 
void clear_last_error ()
 
void set_error (Error code, const std::string message)
 
template<typename Func , typename... Args>
void clear_last_error_and_catch (Func &&exception_prone_func, Args &&... args)
 
void gaussian_blur_fft (uint8_t *image, size_t width, size_t height, double sigma)
 
void invert_image (uint8_t *ptr, int width, int height)
 
void threshold_image (uint8_t *ptr, const int width, const int height, const int num_thresholds)
 
void black_threshold_image (uint8_t *ptr, const int width, const int height, const int num_thresholds)
 
void 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)
 
void bilateral_filter (uint8_t *image, size_t width, size_t height, double sigma_spatial, double sigma_range, uint8_t color_space)
 
std::string labels_to_svg (const uint8_t *data, const int32_t *labels, const int width, const int height, const int min_area)
 

Variables

thread_local Error last_error
 
thread_local std::string last_error_message
 

Detailed Description

Note
All image buffers are assumed to be stored in row-major order, unless otherwise noted.

Enumeration Type Documentation

◆ Error

enum class img2num::Error
strong

Definition at line 8 of file Error.h.

8{ OK = 0, BAD_ALLOC = 1, INVALID_ARGUMENT = 2, RUNTIME = 3, UNKNOWN = 4 };

Function Documentation

◆ 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 
)

◆ black_threshold_image()

void img2num::black_threshold_image ( uint8_t *  ptr,
const int  width,
const int  height,
const int  num_thresholds 
)

◆ clear_last_error_and_catch()

template<typename Func , typename... Args>
void img2num::clear_last_error_and_catch ( Func &&  exception_prone_func,
Args &&...  args 
)

Definition at line 25 of file Error.h.

25 {
26 clear_last_error(); // Clear any previous error state
27 try {
28 exception_prone_func(std::forward<Args>(args)...); // Call the passed function
29 } catch (const std::bad_alloc& e) {
30 set_error(Error::BAD_ALLOC, e.what());
31 } catch (const std::invalid_argument& e) {
32 set_error(Error::INVALID_ARGUMENT, e.what());
33 } catch (const std::runtime_error& e) {
34 set_error(Error::RUNTIME, e.what());
35 } catch (const std::exception& e) {
36 set_error(Error::UNKNOWN, e.what());
37 } catch (...) {
38 set_error(Error::UNKNOWN, "Unknown exception occurred");
39 }
40}

◆ gaussian_blur_fft()

void img2num::gaussian_blur_fft ( uint8_t *  image,
size_t  width,
size_t  height,
double  sigma 
)

◆ get_last_error()

Error img2num::get_last_error ( )
inline

Definition at line 13 of file Error.h.

13 {
14 return last_error;
15}

◆ get_last_error_message()

const std::string img2num::get_last_error_message ( )
inline

Definition at line 16 of file Error.h.

16 {
17 return last_error_message;
18}

◆ invert_image()

void img2num::invert_image ( uint8_t *  ptr,
int  width,
int  height 
)

◆ 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 
)

◆ labels_to_svg()

std::string img2num::labels_to_svg ( const uint8_t *  data,
const int32_t *  labels,
const int  width,
const int  height,
const int  min_area 
)

◆ threshold_image()

void img2num::threshold_image ( uint8_t *  ptr,
const int  width,
const int  height,
const int  num_thresholds 
)