diff --git a/README.md b/README.md index bc1a1caeb..4341b852a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![Open in Codespaces](https://img.shields.io/badge/-Open%20in%20Codespaces-black?logo=github)](https://codespaces.new/Ryan-Millard/Img2Num) - + C++, C, JavaScript, Python _Img2Num_ converts raster images into clean SVGs with _high accuracy and performance_. diff --git a/bindings/c/include/cimg2num.h b/bindings/c/include/cimg2num.h index bb6d32587..4da5d36f1 100644 --- a/bindings/c/include/cimg2num.h +++ b/bindings/c/include/cimg2num.h @@ -16,6 +16,41 @@ extern "C" { #endif +/// @brief Configuration options for image_to_svg. +/// @ingroup CIMG2NUM_H +typedef struct img2num_ImageToSvgConfig { + + /// Configuration settings for the bilateral filter in image_to_svg. + struct BilateralFilterConfig { + /// Standard deviation for spatial Gaussian (proximity weight). + /// Higher values smooth over larger spatial neighborhoods. + double sigma_spatial; + /// Standard deviation for range Gaussian (intensity similarity weight). + /// Higher values allow blending of more dissimilar pixel intensities. + double sigma_range; + } bilateral_filter; + + /// Configuration settings for K-Means in image_to_svg. + struct KMeansConfig { + /// Number of clusters to compute in K-Means. + /// Roughly represents number of unique colors discovered. + int32_t k; + /// Maximum number of iterations for the K-Means algorithm. + /// The algorithm may terminate earlier if it converges. + int32_t max_iter; + } kmeans; + + /// Minimum area (in pixels) for a region to be included in the SVG. + int min_cluster_area; + + /// Color space flag. + /// - 0 = CIE LAB (more perceptually accurate) + /// - 1 = sRGB (faster). + uint8_t color_space; +} img2num_ImageToSvgConfig; + +img2num_ImageToSvgConfig img2num_ImageToSvgConfig_default(void); + /// @copydoc ::IMG2NUM_H_GAUSSIAN_BLUR_DOC void img2num_gaussian_blur_fft(uint8_t *image, size_t width, size_t height, double sigma); @@ -43,6 +78,9 @@ void img2num_bilateral_filter(uint8_t *image, size_t width, size_t height, doubl char *img2num_labels_to_svg(const uint8_t *data, const int32_t *labels, const int width, const int height, const int min_area); +/// @copydoc ::IMG2NUM_H_IMAGE_TO_SVG_DOC +char *img2num_image_to_svg(const uint8_t *data, const int width, const int height, + const img2num_ImageToSvgConfig *config); #ifdef __cplusplus } #endif diff --git a/bindings/c/src/cimg2num.cpp b/bindings/c/src/cimg2num.cpp index 2ab53bfe9..74777be72 100644 --- a/bindings/c/src/cimg2num.cpp +++ b/bindings/c/src/cimg2num.cpp @@ -7,6 +7,41 @@ extern "C" { +static img2num::ImageToSvgConfig to_cpp(const img2num_ImageToSvgConfig &c) { + return { + .bilateral_filter{ + .sigma_spatial = c.bilateral_filter.sigma_spatial, + .sigma_range = c.bilateral_filter.sigma_range + }, + .kmeans{ + .k = c.kmeans.k, + .max_iter = c.kmeans.max_iter + }, + .min_cluster_area = c.min_cluster_area, + .color_space = c.color_space + }; +} + +static img2num_ImageToSvgConfig to_c(const img2num::ImageToSvgConfig &cpp) { + return { + .bilateral_filter{ + .sigma_spatial = cpp.bilateral_filter.sigma_spatial, + .sigma_range = cpp.bilateral_filter.sigma_range + }, + .kmeans{ + .k = cpp.kmeans.k, + .max_iter = cpp.kmeans.max_iter + }, + .min_cluster_area = cpp.min_cluster_area, + .color_space = cpp.color_space + }; +} + +img2num_ImageToSvgConfig img2num_ImageToSvgConfig_default(void) { + // Use the defaults from the C++ struct + return to_c(img2num::ImageToSvgConfig{}); +} + void img2num_gaussian_blur_fft(uint8_t *image, size_t width, size_t height, double sigma) { img2num::clear_last_error_and_catch(img2num::gaussian_blur_fft, image, width, height, sigma); } @@ -55,4 +90,28 @@ char *img2num_labels_to_svg(const uint8_t *data, const int32_t *labels, const in data, labels, width, height, min_area); return result; } + +char *img2num_image_to_svg(const uint8_t *data, const int width, const int height, + const img2num_ImageToSvgConfig *config) { + img2num_ImageToSvgConfig default_cfg; + + const img2num_ImageToSvgConfig &cfg{config ? *config : default_cfg}; + + char *result{nullptr}; + + img2num::clear_last_error_and_catch( + [&](const uint8_t *d, const int w, const int h) { + std::string svg{ img2num::image_to_svg(d, w, h, to_cpp(cfg)) }; + + result = static_cast(std::malloc(svg.size() + 1)); + if (!result) { + return; // Allocation failed + } + std::memcpy(result, svg.c_str(), svg.size() + 1); + }, + data, width, height + ); + + return result; +} } diff --git a/bindings/js/CMakeLists.txt b/bindings/js/CMakeLists.txt index 678972c58..23e4bc7b8 100644 --- a/bindings/js/CMakeLists.txt +++ b/bindings/js/CMakeLists.txt @@ -1,14 +1,14 @@ cmake_minimum_required(VERSION 3.16) -project(JSBindings LANGUAGES CXX) +project(JSBindings LANGUAGES C) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 17) +set(CMAKE_C_STANDARD_REQUIRED ON) if(NOT EMSCRIPTEN) message(FATAL_ERROR "Emscripten is required to build JS bindings.") endif() -file(GLOB_RECURSE BINDING_SRC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") +file(GLOB_RECURSE BINDING_SRC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c") add_executable(img2num_wasm ${BINDING_SRC}) diff --git a/bindings/js/src/wasm_wrapper.cpp b/bindings/js/src/wasm_wrapper.c similarity index 70% rename from bindings/js/src/wasm_wrapper.cpp rename to bindings/js/src/wasm_wrapper.c index 3e3cf2726..ef5cd7143 100644 --- a/bindings/js/src/wasm_wrapper.cpp +++ b/bindings/js/src/wasm_wrapper.c @@ -1,7 +1,6 @@ #include #include -extern "C" { EMSCRIPTEN_KEEPALIVE void gaussian_blur_fft(uint8_t *image, size_t width, size_t height, double sigma) { img2num_gaussian_blur_fft(image, width, height, sigma); @@ -37,4 +36,19 @@ EMSCRIPTEN_KEEPALIVE char *labels_to_svg(uint8_t *data, int32_t *labels, const i const int height, const int min_area) { return img2num_labels_to_svg(data, labels, width, height, min_area); } + +EMSCRIPTEN_KEEPALIVE char *image_to_svg(const uint8_t *data, const int width, const int height, + double sigma_spatial, double sigma_range, const int32_t k, + const int32_t max_iter, const int min_area, + const uint8_t color_space) { + img2num_ImageToSvgConfig config = img2num_ImageToSvgConfig_default(); + + config.bilateral_filter.sigma_spatial = sigma_spatial; + config.bilateral_filter.sigma_range = sigma_range; + config.kmeans.k = k; + config.kmeans.max_iter = max_iter; + config.min_cluster_area = min_area; + config.color_space = color_space; + + return img2num_image_to_svg(data, width, height, &config); } diff --git a/bindings/py/src/img2num_pybind.cpp b/bindings/py/src/img2num_pybind.cpp index 137cc51a6..5ba50bf6d 100644 --- a/bindings/py/src/img2num_pybind.cpp +++ b/bindings/py/src/img2num_pybind.cpp @@ -1,11 +1,15 @@ #include #include #include +#include #include +#include +#include +#include PYBIND11_MODULE(_img2num, m) { - m.doc() = "Python bindings for the img2num C library"; + m.doc() = "Python bindings for the img2num C++ library"; // ----------------------------------------------------------------------- // All Functions return new image data @@ -91,12 +95,12 @@ PYBIND11_MODULE(_img2num, m) { auto out_data = pybind11::array_t(data_buf.shape); auto out_labels = pybind11::array_t({(ssize_t)height, (ssize_t)width}); - auto out_data_ptr = static_cast(out_data.mutable_data()); - auto out_labels_ptr = static_cast(out_labels.mutable_data()); + auto out_data_ptr = static_cast(out_data.mutable_data()); + auto out_labels_ptr = static_cast(out_labels.mutable_data()); // Call C function - img2num::kmeans(static_cast(data_buf.ptr), out_data_ptr, out_labels_ptr, - width, height, k, max_iter, color_space); + img2num::kmeans(static_cast(data_buf.ptr), out_data_ptr, + out_labels_ptr, width, height, k, max_iter, color_space); // Return a tuple of (out_data, out_labels) return pybind11::make_tuple(out_data, out_labels); @@ -110,8 +114,8 @@ PYBIND11_MODULE(_img2num, m) { [](pybind11::array_t data, pybind11::array_t labels, int width, int height, int min_area) { - const uint8_t* data_ptr{static_cast(data.request().ptr)}; - const int32_t* labels_ptr{static_cast(labels.request().ptr)}; + const uint8_t *data_ptr{static_cast(data.request().ptr)}; + const int32_t *labels_ptr{static_cast(labels.request().ptr)}; std::string svg{img2num::labels_to_svg(data_ptr, labels_ptr, width, height, min_area)}; pybind11::str svg_py_str(std::move(svg)); @@ -120,4 +124,87 @@ PYBIND11_MODULE(_img2num, m) { }, pybind11::arg("data"), pybind11::arg("labels"), pybind11::arg("width"), pybind11::arg("height"), pybind11::arg("min_area"), "Convert labels to SVG string"); + + // ---------------------- Config Structs ---------------------- + pybind11::class_ config(m, "ImageToSvgConfig"); + pybind11::class_(config, + "BilateralFilterConfig") + .def(pybind11::init<>()) + .def_readwrite("sigma_spatial", + &img2num::ImageToSvgConfig::BilateralFilterConfig::sigma_spatial) + .def_readwrite("sigma_range", + &img2num::ImageToSvgConfig::BilateralFilterConfig::sigma_range) + .def("__repr__", [](const img2num::ImageToSvgConfig::BilateralFilterConfig &c) { + return "{'sigma_spatial': " + std::to_string(c.sigma_spatial) + + ", 'sigma_range': " + std::to_string(c.sigma_range) + "}"; + }); + pybind11::class_(config, "KMeansConfig") + .def(pybind11::init<>()) + .def_readwrite("k", &img2num::ImageToSvgConfig::KMeansConfig::k) + .def_readwrite("max_iter", &img2num::ImageToSvgConfig::KMeansConfig::max_iter) + .def("__repr__", [](const img2num::ImageToSvgConfig::KMeansConfig &c) { + return "{'k': " + std::to_string(c.k) + ", 'max_iter': " + std::to_string(c.max_iter) + + "}"; + }); + + config + .def(pybind11::init([](pybind11::dict bf_dict, pybind11::dict km_dict, + pybind11::kwargs kwargs) { + // hand over ownership to python + std::unique_ptr c = + std::make_unique(); + if (bf_dict.contains("sigma_spatial")) + c->bilateral_filter.sigma_spatial = bf_dict["sigma_spatial"].cast(); + if (bf_dict.contains("sigma_range")) + c->bilateral_filter.sigma_range = bf_dict["sigma_range"].cast(); + + // 3. Process KMeans overrides from the 'km' dictionary + if (km_dict.contains("k")) c->kmeans.k = km_dict["k"].cast(); + if (km_dict.contains("max_iter")) + c->kmeans.max_iter = km_dict["max_iter"].cast(); + + // 4. Process remaining top-level kwargs (like color_space or min_cluster_area) + if (kwargs.contains("min_cluster_area")) + c->min_cluster_area = kwargs["min_cluster_area"].cast(); + if (kwargs.contains("color_space")) + c->color_space = kwargs["color_space"].cast(); + + return c; + }), + pybind11::arg("bilateral_filter") = pybind11::dict(), // Defaults to empty dict + pybind11::arg("kmeans") = pybind11::dict() // Defaults to empty dict + ) + .def_readwrite("bilateral_filter", &img2num::ImageToSvgConfig::bilateral_filter) + .def_readwrite("min_cluster_area", &img2num::ImageToSvgConfig::min_cluster_area) + .def_readwrite("color_space", &img2num::ImageToSvgConfig::color_space) + .def_readwrite("kmeans", &img2num::ImageToSvgConfig::kmeans) + .def("__repr__", [](const img2num::ImageToSvgConfig &c) { + // We use pybind11::repr() to trigger the __repr__ of the nested objects + std::stringstream ss; + ss << "() << ", " + << "min_cluster_area: " << c.min_cluster_area << ", " + << "color_space: " << (int)c.color_space << ", " + << "kmeans: " << pybind11::repr(pybind11::cast(c.kmeans)).cast() + << "}>"; + return ss.str(); + }); + + m.def( + "image_to_svg", + [](pybind11::array_t data, int width, int height, + const img2num::ImageToSvgConfig& cfg) { + + const uint8_t* data_ptr{static_cast(data.request().ptr)}; + + std::string svg{img2num::image_to_svg(data_ptr, width, height, cfg)}; + + return pybind11::str(std::move(svg)); + }, + pybind11::arg("data"), + pybind11::arg("width"), + pybind11::arg("height"), + pybind11::arg("cfg"), + "Convert Image to SVG string"); } diff --git a/core/include/img2num.h b/core/include/img2num.h index 1d60b4d6d..97d361a17 100644 --- a/core/include/img2num.h +++ b/core/include/img2num.h @@ -15,6 +15,39 @@ /// @note All image buffers are assumed to be stored in row-major order, unless otherwise noted. namespace img2num { +/// @brief Configuration options for image_to_svg. +/// @ingroup IMG2NUM_H +struct ImageToSvgConfig { + + /// Configuration settings for the bilateral filter in image_to_svg. + struct BilateralFilterConfig { + /// Standard deviation for spatial Gaussian (proximity weight). + /// Higher values smooth over larger spatial neighborhoods. + double sigma_spatial = 3.0; + /// Standard deviation for range Gaussian (intensity similarity weight). + /// Higher values allow blending of more dissimilar pixel intensities. + double sigma_range = 50.0; + } bilateral_filter; + + /// Configuration settings for K-Means in image_to_svg. + struct KMeansConfig { + /// Number of clusters to compute in K-Means. + /// Roughly represents number of unique colors discovered. + int32_t k = 16; + /// Maximum number of iterations for the K-Means algorithm. + /// The algorithm may terminate earlier if it converges. + int32_t max_iter = 100; + } kmeans; + + /// Minimum area (in pixels) for a region to be included in the SVG. + int min_cluster_area = 100; + + /// Color space flag. + /// - 0 = CIE LAB (more perceptually accurate) + /// - 1 = sRGB (faster). + uint8_t color_space = 0; +}; + /// @copydoc IMG2NUM_H_GAUSSIAN_BLUR_DOC void gaussian_blur_fft(uint8_t *image, size_t width, size_t height, double sigma); @@ -40,6 +73,11 @@ void bilateral_filter(uint8_t *image, size_t width, size_t height, double sigma_ /// @copydoc IMG2NUM_H_LABELS_TO_SVG_DOC std::string labels_to_svg(const uint8_t *data, const int32_t *labels, const int width, const int height, const int min_area); + +/// @copydoc IMG2NUM_H_IMAGE_TO_SVG_DOC +std::string image_to_svg(const uint8_t *data, const int width, const int height, + const ImageToSvgConfig &config); + } // namespace img2num #endif // IMG2NUM_H diff --git a/core/include/internal/gpu.h b/core/include/internal/gpu.h index 5b1e2ae75..19e7e7eda 100644 --- a/core/include/internal/gpu.h +++ b/core/include/internal/gpu.h @@ -257,6 +257,7 @@ class GPU { adapter = nullptr; queue = nullptr; instance = nullptr; + gpu_initialized = false; }; }; diff --git a/core/src/internal/image_to_svg.cpp b/core/src/internal/image_to_svg.cpp new file mode 100644 index 000000000..d02459a6b --- /dev/null +++ b/core/src/internal/image_to_svg.cpp @@ -0,0 +1,24 @@ +#include +#include + +#include "img2num.h" + +namespace img2num { +std::string image_to_svg(const uint8_t* data, const int width, const int height, + const ImageToSvgConfig& config) { + // self deallocate + std::vector img_data(static_cast(width) * static_cast(height) * 4); + std::vector out_data(static_cast(width) * static_cast(height) * 4); + std::vector out_labels(static_cast(width) * static_cast(height)); + + std::memcpy(img_data.data(), data, + static_cast(width) * static_cast(height) * 4); + bilateral_filter(img_data.data(), width, height, config.bilateral_filter.sigma_spatial, + config.bilateral_filter.sigma_range, config.color_space); + kmeans(img_data.data(), out_data.data(), out_labels.data(), width, height, config.kmeans.k, + config.kmeans.max_iter, config.color_space); + std::string svg{labels_to_svg(data, out_labels.data(), width, height, config.min_cluster_area)}; + + return svg; +} +} // namespace img2num \ No newline at end of file diff --git a/core/src/internal/kmeans.cpp b/core/src/internal/kmeans.cpp index 768495b7d..23457dec7 100644 --- a/core/src/internal/kmeans.cpp +++ b/core/src/internal/kmeans.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -243,10 +242,8 @@ void kmeans(const uint8_t *data, uint8_t *out_data, int32_t *out_labels, const i GPU::getClassInstance().init_gpu(); if (GPU::getClassInstance().is_initialized()) { - std::cout << "kmeans gpu" << std::endl; kmeans_gpu(data, out_data, out_labels, width, height, k, max_iter, color_space); } else { - std::cout << "kmeans cpu" << std::endl; kmeans_cpu(data, out_data, out_labels, width, height, k, max_iter, color_space); } } diff --git a/doxygen/img2num.h.dox b/doxygen/img2num.h.dox index e44d517e3..291aee375 100644 --- a/doxygen/img2num.h.dox +++ b/doxygen/img2num.h.dox @@ -87,3 +87,16 @@ /// @return std::string A valid SVG string containing the data. /// @note Dox File: `doxygen/img2num.h.dox` /// + +#define IMG2NUM_H_IMAGE_TO_SVG_DOC +/// @def IMG2NUM_H_IMAGE_TO_SVG_DOC +/// @brief Convert labeled regions of an image into an SVG string. +/// @ingroup IMG2NUM_H +/// @param data Pointer to image data buffer. +/// @param width Width of the image in pixels. +/// @param height Height of the image in pixels. +/// @param config img2num_ImageToSvgConfig Configuration Struct. +/// > See @ref img2num::ImageToSvgConfig. +/// @return std::string An SVG string containing data roughly approximate to the input image. +/// @note Dox File: `doxygen/img2num.h.dox` +/// diff --git a/example-apps/console-c/CMakeLists.txt b/example-apps/console-c/CMakeLists.txt index c73945981..f318d071b 100644 --- a/example-apps/console-c/CMakeLists.txt +++ b/example-apps/console-c/CMakeLists.txt @@ -24,4 +24,4 @@ target_compile_definitions(console_c_app PRIVATE ) # Link against the C bindings -target_link_libraries(console_c_app PRIVATE CImg2Num Img2Num m) +target_link_libraries(console_c_app PRIVATE CImg2Num m) diff --git a/example-apps/console-c/main.c b/example-apps/console-c/main.c index 0faf5e2e4..579f69104 100644 --- a/example-apps/console-c/main.c +++ b/example-apps/console-c/main.c @@ -73,8 +73,20 @@ int main(int argc, char** argv) { // Generate SVG char* res_svg = img2num_labels_to_svg(img_data, out_labels, width, height, 100); + img2num_ImageToSvgConfig cfg = img2num_ImageToSvgConfig_default(); + char* res_svg2 = img2num_image_to_svg(image_data_original, width, height, &cfg); + if (res_svg == NULL) { - fprintf(stderr, "Failed to generate SVG\n"); + fprintf(stderr, "Failed to generate SVG step-by-step\n"); + stbi_image_free(image_data_original); + free(img_data); + free(out_data); + free(out_labels); + return 1; + } + + if (res_svg2 == NULL) { + fprintf(stderr, "Failed to generate SVG in unified call\n"); stbi_image_free(image_data_original); free(img_data); free(out_data); @@ -120,5 +132,6 @@ int main(int argc, char** argv) { free(out_data); free(out_labels); free(res_svg); + free(res_svg2); return exit_code; } diff --git a/example-apps/console-cpp/main.cpp b/example-apps/console-cpp/main.cpp index e6cd7bbe4..47c6dbe63 100644 --- a/example-apps/console-cpp/main.cpp +++ b/example-apps/console-cpp/main.cpp @@ -66,6 +66,10 @@ int main(int argc, char** argv) { // Generate SVG std::string res_svg{img2num::labels_to_svg(img_data, out_labels, width, height, 100)}; + img2num::ImageToSvgConfig config; + config.kmeans.k = 32; + std::string res_svg2{img2num::image_to_svg(img_data, width, height, config)}; + // Save the blurred image std::string out_path{std::string(OUT_DIR) + "/console-cpp-output.png"}; std::string kmeans_path{std::string(OUT_DIR) + "/console-cpp-kmeans.png"}; @@ -87,7 +91,7 @@ int main(int argc, char** argv) { exit_code = 1; } if (exit_code == 0) { - svgFile << res_svg; + svgFile << res_svg2; svgFile.close(); } diff --git a/example-apps/console-py/main.py b/example-apps/console-py/main.py index 94cb07334..461d91745 100644 --- a/example-apps/console-py/main.py +++ b/example-apps/console-py/main.py @@ -30,5 +30,13 @@ def main(): with open(os.path.join(OUTDIR, "result.svg"),"w") as f: f.writelines(res_svg) + # res_svg2 should match res_svg + cfg = img2num.ImageToSvgConfig(kmeans = {"k": 16}) + print(cfg) + + res_svg2 = img2num.image_to_svg(img, config=cfg) + with open(os.path.join(OUTDIR, "result2.svg"),"w") as f: + f.writelines(res_svg2) + if __name__ == "__main__": main() diff --git a/packages/js/safeWasmWrappers.js b/packages/js/safeWasmWrappers.js index 78d4a3dd7..504c43556 100644 --- a/packages/js/safeWasmWrappers.js +++ b/packages/js/safeWasmWrappers.js @@ -31,16 +31,16 @@ initWasmWorker(); * * @async * @function gaussianBlur - * @param {Object} __named_parameters - The input options. - * @property {Uint8ClampedArray} __named_parameters.pixels - The image pixel data (flat RGBA array). - * @property {number} __named_parameters.width - The width of the image. - * @property {number} __named_parameters.height - The height of the image. - * @property {number} [__named_parameters.sigma_pixels=width*0.005] - Standard deviation of the Gaussian blur (default=width*0.005; 5% of width). + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - The image pixel data (flat RGBA array). + * @param {number} options.width - The width of the image. + * @param {number} options.height - The height of the image. + * @param {number} [options.sigma_pixels=width*0.005] - Standard deviation of the Gaussian blur (default=width*0.005; 5% of width). * @returns {Promise} The blurred image pixels. * @throws {Error} If the WASM function fails or memory allocation fails. * @example * const blurred = await gaussianBlur({ pixels, width, height }); - * @todo Consider adding support for multiple channels or alpha-only blurs. + * @todo Fix FFT zero-padding bug around edges of the image. * @variation Standard Gaussian blur using FFT * @since 0.0.0 */ @@ -65,13 +65,13 @@ export const gaussianBlur = async ({ pixels, width, height, sigma_pixels = width * * @async * @function bilateralFilter - * @param {Object} __named_parameters - The input options. - * @property {Uint8ClampedArray} __named_parameters.pixels - The image pixel data (flat RGBA array). - * @property {number} __named_parameters.width - The width of the image. - * @property {number} __named_parameters.height - The height of the image. - * @property {number} [__named_parameters.sigma_spatial=3] - Spatial standard deviation. - * @property {number} [__named_parameters.sigma_range=50] - Range (color) standard deviation. - * @property {number} [__named_parameters.color_space=0] - Color space mode (0: CIE LAB; 1: sRGB). + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - The image pixel data (flat RGBA array). + * @param {number} options.width - The width of the image. + * @param {number} options.height - The height of the image. + * @param {number} [options.sigma_spatial=3] - Spatial standard deviation. + * @param {number} [options.sigma_range=50] - Range (color) standard deviation. + * @param {number} [options.color_space=0] - Color space mode (0: CIE LAB; 1: sRGB). * @returns {Promise} The filtered image pixels. * @throws {Error} If the WASM function fails. * @example @@ -97,11 +97,11 @@ export const bilateralFilter = async ({ pixels, width, height, sigma_spatial = 3 * * @async * @function blackThreshold - * @param {Object} __named_parameters - The input options. - * @property {Uint8ClampedArray} __named_parameters.pixels - The image pixel data (flat RGBA array). - * @property {number} __named_parameters.width - The width of the image. - * @property {number} __named_parameters.height - The height of the image. - * @property {number} __named_parameters.num_colors - Number of colors to reduce the image to. + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - The image pixel data (flat RGBA array). + * @param {number} options.width - The width of the image. + * @param {number} options.height - The height of the image. + * @param {number} options.num_colors - Number of colors to reduce the image to. * @returns {Promise} The thresholded image pixels. * @throws {Error} If the WASM function fails. * @example @@ -132,15 +132,15 @@ export const blackThreshold = async ({ pixels, width, height, num_colors }) => { * * @async * @function kmeans - * @param {Object} __named_parameters - The input options. - * @property {Uint8ClampedArray} __named_parameters.pixels - Original image pixels. - * @property {Uint8ClampedArray} [__named_parameters.out_pixels=new Uint8ClampedArray(pixels.length)] - Output pixels array. - * @property {Int32Array} [__named_parameters.out_labels=new Int32Array(pixels.length/4)] - Output labels array. - * @property {number} __named_parameters.width - Image width. - * @property {number} __named_parameters.height - Image height. - * @property {number} __named_parameters.num_colors - Number of color clusters. - * @property {number} [__named_parameters.max_iter=100] - Maximum number of iterations. - * @property {number} [__named_parameters.color_space=0] - Color space mode. + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - Original image pixels. + * @param {Uint8ClampedArray} [options.out_pixels=new Uint8ClampedArray(pixels.length)] - Output pixels array. + * @param {Int32Array} [options.out_labels=new Int32Array(pixels.length/4)] - Output labels array. + * @param {number} options.width - Image width. + * @param {number} options.height - Image height. + * @param {number} options.num_colors - Number of color clusters. + * @param {number} [options.max_iter=100] - Maximum number of iterations. + * @param {number} [options.color_space=0] - Color space mode. * @returns {Promise<{pixels: Uint8ClampedArray, labels: Int32Array}>} Clustered pixels and labels. * @throws {Error} If the WASM function fails or iterations do not converge. * @example @@ -178,18 +178,17 @@ export const kmeans = async ({ * * @async * @function findContours - * @param {Object} __named_parameters - The input options. - * @property {Uint8ClampedArray} __named_parameters.pixels - Original image pixels. - * @property {Int32Array} __named_parameters.labels - Label array from clustering (e.g., K-Means) or segmentation. - * @property {number} __named_parameters.width - Image width. - * @property {number} __named_parameters.height - Image height. - * @property {number} [__named_parameters.min_area=100] - Minimum area of a region to be considered a contour. - * @returns {Promise<{svg: string, visualization: Uint8ClampedArray}>} Generated SVG and optionally pixels with visualized contours. + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - Original image pixels. + * @param {Int32Array} options.labels - Label array from clustering (e.g., K-Means) or segmentation. + * @param {number} options.width - Image width. + * @param {number} options.height - Image height. + * @param {number} [options.min_area=100] - Minimum area of a region to be considered a contour. + * @returns {Promise<{svg: string>} Generated SVG. * @throws {Error} If the WASM function fails or input labels are invalid. * @example - * const { svg, visualization } = await findContours({ pixels, labels, width, height }); - * @todo Support additional visualization options like color-coded regions. - * @variation Contour extraction with optional visualization + * const { svg } = await findContours({ pixels, labels, width, height }); + * @variation Converts labeled (from a clustering algorithm, e.g. K-Means) image into an SVG. * @since 0.0.0 */ export const findContours = async ({ pixels, labels, width, height, min_area = 100 }) => { @@ -202,5 +201,40 @@ export const findContours = async ({ pixels, labels, width, height, min_area = 1 ], returnType: "string", }); - return { svg: result.returnValue, visualization: result.output.pixels }; + return { svg: result.returnValue }; +}; + +/** + * @summary Convert raster images (e.g., JPEG, PNG) to SVGs. + * + * @description + * Convert an input raster image into an SVG. A unification of `bilateralFilter`, `kmeans`, and `findContours`. + * + * @async + * @function imageToSvg + * @param {Object} options - The input options. + * @param {Uint8ClampedArray} options.pixels - Original image pixels. + * @param {number} options.width - Image width. + * @param {number} options.height - Image height. + * @param {number} [options.sigma_spatial=3] - Spatial standard deviation. + * @param {number} [options.sigma_range=50] - Range (color) standard deviation. + * @param {number} [options.num_colors=16] - Number of color clusters. + * @param {number} [options.max_iter=100] - Maximum number of iterations. + * @param {number} [options.min_area=100] - Minimum area of a region to be considered a contour. + * @param {number} [options.color_space=0] - Color space mode. + * @returns {Promise<{svg: string}>} Generated SVG. + * @throws {Error} If the WASM function fails or input labels are invalid. + * @example + * const { svg } = await findContours({ pixels, labels, width, height }); + * @variation Convert a raster image (e.g., PNG, JPG) into an SVG. + * @since 0.0.0 + */ +export const imageToSvg = async ({ pixels, width, height, sigma_spatial = 3, sigma_range = 50, num_colors = 16, max_iter = 100, min_area = 100, color_space = 0 }) => { + const result = await callWasm({ + funcName: "image_to_svg", + args: { pixels, width, height, sigma_spatial, sigma_range, num_colors, max_iter, min_area, color_space }, + bufferKeys: [{ key: "pixels", type: "Uint8ClampedArray" }], + returnType: "string", + }); + return { svg: result.returnValue }; }; diff --git a/packages/py/img2num/api.py b/packages/py/img2num/api.py index 2f4729b94..09b995941 100644 --- a/packages/py/img2num/api.py +++ b/packages/py/img2num/api.py @@ -1,4 +1,6 @@ +from typing import Tuple import numpy as np +import numpy.typing as npt import inspect import functools from ._img2num import ( @@ -9,6 +11,8 @@ bilateral_filter as _bilateral_filter, kmeans as _kmeans, labels_to_svg as _labels_to_svg, + image_to_svg as _image_to_svg, + ImageToSvgConfig ) def _inject_dims(image_arg="image"): @@ -33,29 +37,41 @@ def wrapper(*args, **kwargs): @_inject_dims("image") -def gaussian_blur_fft(image, sigma, *, width, height): +def gaussian_blur_fft(image: npt.NDArray[np.uint8], sigma: float, *, width: int, height: int) -> npt.NDArray[np.uint8]: return _gaussian_blur_fft(image, width, height, sigma) @_inject_dims("image") -def invert_image(image, *, width, height): +def invert_image(image: npt.NDArray[np.uint8], *, width: int, height: int) -> npt.NDArray[np.uint8]: return _invert_image(image, width, height) @_inject_dims("image") -def threshold_image(image, num_thresholds, *, width, height): +def threshold_image(image: npt.NDArray[np.uint8], num_thresholds: int, *, width: int, height: int) -> npt.NDArray[np.uint8]: return _threshold_image(image, width, height, num_thresholds) @_inject_dims("image") -def black_threshold_image(image, num_thresholds, *, width, height): +def black_threshold_image(image: npt.NDArray[np.uint8], num_thresholds: int, *, width: int, height: int) -> npt.NDArray[np.uint8]: return _black_threshold_image(image, width, height, num_thresholds) @_inject_dims("image") -def bilateral_filter(image, sigma_spatial, sigma_range, color_space, *, width, height): +def bilateral_filter(image: npt.NDArray[np.uint8], sigma_spatial: float, sigma_range: float, color_space: int, *, width: int, height: int) -> npt.NDArray[np.uint8]: return _bilateral_filter(image, width, height, sigma_spatial, sigma_range, color_space) @_inject_dims("data") -def kmeans(data, k, max_iter, color_space, *, width, height): +def kmeans(data: npt.NDArray[np.uint8], k: int, max_iter: int, color_space: int, *, width: int, height: int) -> Tuple[npt.NDArray[np.uint8], npt.NDArray[int]]: return _kmeans(data, width, height, k, max_iter, color_space) @_inject_dims("data") -def labels_to_svg(data, labels, min_area, *, width, height): +def labels_to_svg(data: npt.NDArray[np.uint8], labels: npt.NDArray[int], min_area: int, *, width: int, height: int) -> str: return _labels_to_svg(data, labels, width, height, min_area) + +@_inject_dims("image") +def image_to_svg(image: npt.NDArray[np.uint8], *, width: int, height: int, config=None) -> str: + _config = ImageToSvgConfig() if config is None else config + + return _image_to_svg( + image, + width, + height, + # Use default + _config, + ) diff --git a/uv.lock b/uv.lock index 0d17ec598..b738142d0 100644 --- a/uv.lock +++ b/uv.lock @@ -1,9 +1,5 @@ version = 1 requires-python = ">=3.10" -resolution-markers = [ - "python_full_version >= '3.11'", - "python_full_version < '3.11'", -] [manifest] members = [ @@ -17,8 +13,7 @@ name = "console-py" version = "0.0.0" source = { editable = "example-apps/console-py" } dependencies = [ - { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "numpy", version = "2.4.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "numpy" }, { name = "opencv-python" }, ] @@ -33,8 +28,7 @@ name = "img2num" version = "0.0.0" source = { editable = "packages/py" } dependencies = [ - { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "numpy", version = "2.4.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "numpy" }, ] [package.metadata] @@ -55,9 +49,6 @@ requires-dist = [{ name = "img2num", editable = "packages/py" }] name = "numpy" version = "2.2.6" source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] sdist = { url = "https://files.pythonhosted.org/packages/76/21/7d2a95e4bba9dc13d043ee156a356c0a8f0c6309dff6b21b4d71a073b8a8/numpy-2.2.6.tar.gz", hash = "sha256:e29554e2bef54a90aa5cc07da6ce955accb83f21ab5de01a62c8478897b264fd", size = 20276440 } wheels = [ { url = "https://files.pythonhosted.org/packages/9a/3e/ed6db5be21ce87955c0cbd3009f2803f59fa08df21b5df06862e2d8e2bdd/numpy-2.2.6-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b412caa66f72040e6d268491a59f2c43bf03eb6c96dd8f0307829feb7fa2b6fb", size = 21165245 }, @@ -116,95 +107,12 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/37/48/ac2a9584402fb6c0cd5b5d1a91dcf176b15760130dd386bbafdbfe3640bf/numpy-2.2.6-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:d042d24c90c41b54fd506da306759e06e568864df8ec17ccc17e9e884634fd00", size = 12812666 }, ] -[[package]] -name = "numpy" -version = "2.4.4" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version >= '3.11'", -] -sdist = { url = "https://files.pythonhosted.org/packages/d7/9f/b8cef5bffa569759033adda9481211426f12f53299629b410340795c2514/numpy-2.4.4.tar.gz", hash = "sha256:2d390634c5182175533585cc89f3608a4682ccb173cc9bb940b2881c8d6f8fa0", size = 20731587 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/ef/c6/4218570d8c8ecc9704b5157a3348e486e84ef4be0ed3e38218ab473c83d2/numpy-2.4.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f983334aea213c99992053ede6168500e5f086ce74fbc4acc3f2b00f5762e9db", size = 16976799 }, - { url = "https://files.pythonhosted.org/packages/dd/92/b4d922c4a5f5dab9ed44e6153908a5c665b71acf183a83b93b690996e39b/numpy-2.4.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:72944b19f2324114e9dc86a159787333b77874143efcf89a5167ef83cfee8af0", size = 14971552 }, - { url = "https://files.pythonhosted.org/packages/8a/dc/df98c095978fa6ee7b9a9387d1d58cbb3d232d0e69ad169a4ce784bde4fd/numpy-2.4.4-cp311-cp311-macosx_14_0_arm64.whl", hash = "sha256:86b6f55f5a352b48d7fbfd2dbc3d5b780b2d79f4d3c121f33eb6efb22e9a2015", size = 5476566 }, - { url = "https://files.pythonhosted.org/packages/28/34/b3fdcec6e725409223dd27356bdf5a3c2cc2282e428218ecc9cb7acc9763/numpy-2.4.4-cp311-cp311-macosx_14_0_x86_64.whl", hash = "sha256:ba1f4fc670ed79f876f70082eff4f9583c15fb9a4b89d6188412de4d18ae2f40", size = 6806482 }, - { url = "https://files.pythonhosted.org/packages/68/62/63417c13aa35d57bee1337c67446761dc25ea6543130cf868eace6e8157b/numpy-2.4.4-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8a87ec22c87be071b6bdbd27920b129b94f2fc964358ce38f3822635a3e2e03d", size = 15973376 }, - { url = "https://files.pythonhosted.org/packages/cf/c5/9fcb7e0e69cef59cf10c746b84f7d58b08bc66a6b7d459783c5a4f6101a6/numpy-2.4.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:df3775294accfdd75f32c74ae39fcba920c9a378a2fc18a12b6820aa8c1fb502", size = 16925137 }, - { url = "https://files.pythonhosted.org/packages/7e/43/80020edacb3f84b9efdd1591120a4296462c23fd8db0dde1666f6ef66f13/numpy-2.4.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0d4e437e295f18ec29bc79daf55e8a47a9113df44d66f702f02a293d93a2d6dd", size = 17329414 }, - { url = "https://files.pythonhosted.org/packages/fd/06/af0658593b18a5f73532d377188b964f239eb0894e664a6c12f484472f97/numpy-2.4.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:6aa3236c78803afbcb255045fbef97a9e25a1f6c9888357d205ddc42f4d6eba5", size = 18658397 }, - { url = "https://files.pythonhosted.org/packages/e6/ce/13a09ed65f5d0ce5c7dd0669250374c6e379910f97af2c08c57b0608eee4/numpy-2.4.4-cp311-cp311-win32.whl", hash = "sha256:30caa73029a225b2d40d9fae193e008e24b2026b7ee1a867b7ee8d96ca1a448e", size = 6239499 }, - { url = "https://files.pythonhosted.org/packages/bd/63/05d193dbb4b5eec1eca73822d80da98b511f8328ad4ae3ca4caf0f4db91d/numpy-2.4.4-cp311-cp311-win_amd64.whl", hash = "sha256:6bbe4eb67390b0a0265a2c25458f6b90a409d5d069f1041e6aff1e27e3d9a79e", size = 12614257 }, - { url = "https://files.pythonhosted.org/packages/87/c5/8168052f080c26fa984c413305012be54741c9d0d74abd7fbeeccae3889f/numpy-2.4.4-cp311-cp311-win_arm64.whl", hash = "sha256:fcfe2045fd2e8f3cb0ce9d4ba6dba6333b8fa05bb8a4939c908cd43322d14c7e", size = 10486775 }, - { url = "https://files.pythonhosted.org/packages/28/05/32396bec30fb2263770ee910142f49c1476d08e8ad41abf8403806b520ce/numpy-2.4.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:15716cfef24d3a9762e3acdf87e27f58dc823d1348f765bbea6bef8c639bfa1b", size = 16689272 }, - { url = "https://files.pythonhosted.org/packages/c5/f3/a983d28637bfcd763a9c7aafdb6d5c0ebf3d487d1e1459ffdb57e2f01117/numpy-2.4.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:23cbfd4c17357c81021f21540da84ee282b9c8fba38a03b7b9d09ba6b951421e", size = 14699573 }, - { url = "https://files.pythonhosted.org/packages/9b/fd/e5ecca1e78c05106d98028114f5c00d3eddb41207686b2b7de3e477b0e22/numpy-2.4.4-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:8b3b60bb7cba2c8c81837661c488637eee696f59a877788a396d33150c35d842", size = 5204782 }, - { url = "https://files.pythonhosted.org/packages/de/2f/702a4594413c1a8632092beae8aba00f1d67947389369b3777aed783fdca/numpy-2.4.4-cp312-cp312-macosx_14_0_x86_64.whl", hash = "sha256:e4a010c27ff6f210ff4c6ef34394cd61470d01014439b192ec22552ee867f2a8", size = 6552038 }, - { url = "https://files.pythonhosted.org/packages/7f/37/eed308a8f56cba4d1fdf467a4fc67ef4ff4bf1c888f5fc980481890104b1/numpy-2.4.4-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f9e75681b59ddaa5e659898085ae0eaea229d054f2ac0c7e563a62205a700121", size = 15670666 }, - { url = "https://files.pythonhosted.org/packages/0a/0d/0e3ecece05b7a7e87ab9fb587855548da437a061326fff64a223b6dcb78a/numpy-2.4.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:81f4a14bee47aec54f883e0cad2d73986640c1590eb9bfaaba7ad17394481e6e", size = 16645480 }, - { url = "https://files.pythonhosted.org/packages/34/49/f2312c154b82a286758ee2f1743336d50651f8b5195db18cdb63675ff649/numpy-2.4.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:62d6b0f03b694173f9fcb1fb317f7222fd0b0b103e784c6549f5e53a27718c44", size = 17020036 }, - { url = "https://files.pythonhosted.org/packages/7b/e9/736d17bd77f1b0ec4f9901aaec129c00d59f5d84d5e79bba540ef12c2330/numpy-2.4.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fbc356aae7adf9e6336d336b9c8111d390a05df88f1805573ebb0807bd06fd1d", size = 18368643 }, - { url = "https://files.pythonhosted.org/packages/63/f6/d417977c5f519b17c8a5c3bc9e8304b0908b0e21136fe43bf628a1343914/numpy-2.4.4-cp312-cp312-win32.whl", hash = "sha256:0d35aea54ad1d420c812bfa0385c71cd7cc5bcf7c65fed95fc2cd02fe8c79827", size = 5961117 }, - { url = "https://files.pythonhosted.org/packages/2d/5b/e1deebf88ff431b01b7406ca3583ab2bbb90972bbe1c568732e49c844f7e/numpy-2.4.4-cp312-cp312-win_amd64.whl", hash = "sha256:b5f0362dc928a6ecd9db58868fca5e48485205e3855957bdedea308f8672ea4a", size = 12320584 }, - { url = "https://files.pythonhosted.org/packages/58/89/e4e856ac82a68c3ed64486a544977d0e7bdd18b8da75b78a577ca31c4395/numpy-2.4.4-cp312-cp312-win_arm64.whl", hash = "sha256:846300f379b5b12cc769334464656bc882e0735d27d9726568bc932fdc49d5ec", size = 10221450 }, - { url = "https://files.pythonhosted.org/packages/14/1d/d0a583ce4fefcc3308806a749a536c201ed6b5ad6e1322e227ee4848979d/numpy-2.4.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:08f2e31ed5e6f04b118e49821397f12767934cfdd12a1ce86a058f91e004ee50", size = 16684933 }, - { url = "https://files.pythonhosted.org/packages/c1/62/2b7a48fbb745d344742c0277f01286dead15f3f68e4f359fbfcf7b48f70f/numpy-2.4.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:e823b8b6edc81e747526f70f71a9c0a07ac4e7ad13020aa736bb7c9d67196115", size = 14694532 }, - { url = "https://files.pythonhosted.org/packages/e5/87/499737bfba066b4a3bebff24a8f1c5b2dee410b209bc6668c9be692580f0/numpy-2.4.4-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:4a19d9dba1a76618dd86b164d608566f393f8ec6ac7c44f0cc879011c45e65af", size = 5199661 }, - { url = "https://files.pythonhosted.org/packages/cd/da/464d551604320d1491bc345efed99b4b7034143a85787aab78d5691d5a0e/numpy-2.4.4-cp313-cp313-macosx_14_0_x86_64.whl", hash = "sha256:d2a8490669bfe99a233298348acc2d824d496dee0e66e31b66a6022c2ad74a5c", size = 6547539 }, - { url = "https://files.pythonhosted.org/packages/7d/90/8d23e3b0dafd024bf31bdec225b3bb5c2dbfa6912f8a53b8659f21216cbf/numpy-2.4.4-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:45dbed2ab436a9e826e302fcdcbe9133f9b0006e5af7168afb8963a6520da103", size = 15668806 }, - { url = "https://files.pythonhosted.org/packages/d1/73/a9d864e42a01896bb5974475438f16086be9ba1f0d19d0bb7a07427c4a8b/numpy-2.4.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c901b15172510173f5cb310eae652908340f8dede90fff9e3bf6c0d8dfd92f83", size = 16632682 }, - { url = "https://files.pythonhosted.org/packages/34/fb/14570d65c3bde4e202a031210475ae9cde9b7686a2e7dc97ee67d2833b35/numpy-2.4.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:99d838547ace2c4aace6c4f76e879ddfe02bb58a80c1549928477862b7a6d6ed", size = 17019810 }, - { url = "https://files.pythonhosted.org/packages/8a/77/2ba9d87081fd41f6d640c83f26fb7351e536b7ce6dd9061b6af5904e8e46/numpy-2.4.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0aec54fd785890ecca25a6003fd9a5aed47ad607bbac5cd64f836ad8666f4959", size = 18357394 }, - { url = "https://files.pythonhosted.org/packages/a2/23/52666c9a41708b0853fa3b1a12c90da38c507a3074883823126d4e9d5b30/numpy-2.4.4-cp313-cp313-win32.whl", hash = "sha256:07077278157d02f65c43b1b26a3886bce886f95d20aabd11f87932750dfb14ed", size = 5959556 }, - { url = "https://files.pythonhosted.org/packages/57/fb/48649b4971cde70d817cf97a2a2fdc0b4d8308569f1dd2f2611959d2e0cf/numpy-2.4.4-cp313-cp313-win_amd64.whl", hash = "sha256:5c70f1cc1c4efbe316a572e2d8b9b9cc44e89b95f79ca3331553fbb63716e2bf", size = 12317311 }, - { url = "https://files.pythonhosted.org/packages/ba/d8/11490cddd564eb4de97b4579ef6bfe6a736cc07e94c1598590ae25415e01/numpy-2.4.4-cp313-cp313-win_arm64.whl", hash = "sha256:ef4059d6e5152fa1a39f888e344c73fdc926e1b2dd58c771d67b0acfbf2aa67d", size = 10222060 }, - { url = "https://files.pythonhosted.org/packages/99/5d/dab4339177a905aad3e2221c915b35202f1ec30d750dd2e5e9d9a72b804b/numpy-2.4.4-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:4bbc7f303d125971f60ec0aaad5e12c62d0d2c925f0ab1273debd0e4ba37aba5", size = 14822302 }, - { url = "https://files.pythonhosted.org/packages/eb/e4/0564a65e7d3d97562ed6f9b0fd0fb0a6f559ee444092f105938b50043876/numpy-2.4.4-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:4d6d57903571f86180eb98f8f0c839fa9ebbfb031356d87f1361be91e433f5b7", size = 5327407 }, - { url = "https://files.pythonhosted.org/packages/29/8d/35a3a6ce5ad371afa58b4700f1c820f8f279948cca32524e0a695b0ded83/numpy-2.4.4-cp313-cp313t-macosx_14_0_x86_64.whl", hash = "sha256:4636de7fd195197b7535f231b5de9e4b36d2c440b6e566d2e4e4746e6af0ca93", size = 6647631 }, - { url = "https://files.pythonhosted.org/packages/f4/da/477731acbd5a58a946c736edfdabb2ac5b34c3d08d1ba1a7b437fa0884df/numpy-2.4.4-cp313-cp313t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ad2e2ef14e0b04e544ea2fa0a36463f847f113d314aa02e5b402fdf910ef309e", size = 15727691 }, - { url = "https://files.pythonhosted.org/packages/e6/db/338535d9b152beabeb511579598418ba0212ce77cf9718edd70262cc4370/numpy-2.4.4-cp313-cp313t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a285b3b96f951841799528cd1f4f01cd70e7e0204b4abebac9463eecfcf2a40", size = 16681241 }, - { url = "https://files.pythonhosted.org/packages/e2/a9/ad248e8f58beb7a0219b413c9c7d8151c5d285f7f946c3e26695bdbbe2df/numpy-2.4.4-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:f8474c4241bc18b750be2abea9d7a9ec84f46ef861dbacf86a4f6e043401f79e", size = 17085767 }, - { url = "https://files.pythonhosted.org/packages/b5/1a/3b88ccd3694681356f70da841630e4725a7264d6a885c8d442a697e1146b/numpy-2.4.4-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:4e874c976154687c1f71715b034739b45c7711bec81db01914770373d125e392", size = 18403169 }, - { url = "https://files.pythonhosted.org/packages/c2/c9/fcfd5d0639222c6eac7f304829b04892ef51c96a75d479214d77e3ce6e33/numpy-2.4.4-cp313-cp313t-win32.whl", hash = "sha256:9c585a1790d5436a5374bac930dad6ed244c046ed91b2b2a3634eb2971d21008", size = 6083477 }, - { url = "https://files.pythonhosted.org/packages/d5/e3/3938a61d1c538aaec8ed6fd6323f57b0c2d2d2219512434c5c878db76553/numpy-2.4.4-cp313-cp313t-win_amd64.whl", hash = "sha256:93e15038125dc1e5345d9b5b68aa7f996ec33b98118d18c6ca0d0b7d6198b7e8", size = 12457487 }, - { url = "https://files.pythonhosted.org/packages/97/6a/7e345032cc60501721ef94e0e30b60f6b0bd601f9174ebd36389a2b86d40/numpy-2.4.4-cp313-cp313t-win_arm64.whl", hash = "sha256:0dfd3f9d3adbe2920b68b5cd3d51444e13a10792ec7154cd0a2f6e74d4ab3233", size = 10292002 }, - { url = "https://files.pythonhosted.org/packages/6e/06/c54062f85f673dd5c04cbe2f14c3acb8c8b95e3384869bb8cc9bff8cb9df/numpy-2.4.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:f169b9a863d34f5d11b8698ead99febeaa17a13ca044961aa8e2662a6c7766a0", size = 16684353 }, - { url = "https://files.pythonhosted.org/packages/4c/39/8a320264a84404c74cc7e79715de85d6130fa07a0898f67fb5cd5bd79908/numpy-2.4.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:2483e4584a1cb3092da4470b38866634bafb223cbcd551ee047633fd2584599a", size = 14704914 }, - { url = "https://files.pythonhosted.org/packages/91/fb/287076b2614e1d1044235f50f03748f31fa287e3dbe6abeb35cdfa351eca/numpy-2.4.4-cp314-cp314-macosx_14_0_arm64.whl", hash = "sha256:2d19e6e2095506d1736b7d80595e0f252d76b89f5e715c35e06e937679ea7d7a", size = 5210005 }, - { url = "https://files.pythonhosted.org/packages/63/eb/fcc338595309910de6ecabfcef2419a9ce24399680bfb149421fa2df1280/numpy-2.4.4-cp314-cp314-macosx_14_0_x86_64.whl", hash = "sha256:6a246d5914aa1c820c9443ddcee9c02bec3e203b0c080349533fae17727dfd1b", size = 6544974 }, - { url = "https://files.pythonhosted.org/packages/44/5d/e7e9044032a716cdfaa3fba27a8e874bf1c5f1912a1ddd4ed071bf8a14a6/numpy-2.4.4-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:989824e9faf85f96ec9c7761cd8d29c531ad857bfa1daa930cba85baaecf1a9a", size = 15684591 }, - { url = "https://files.pythonhosted.org/packages/98/7c/21252050676612625449b4807d6b695b9ce8a7c9e1c197ee6216c8a65c7c/numpy-2.4.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:27a8d92cd10f1382a67d7cf4db7ce18341b66438bdd9f691d7b0e48d104c2a9d", size = 16637700 }, - { url = "https://files.pythonhosted.org/packages/b1/29/56d2bbef9465db24ef25393383d761a1af4f446a1df9b8cded4fe3a5a5d7/numpy-2.4.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:e44319a2953c738205bf3354537979eaa3998ed673395b964c1176083dd46252", size = 17035781 }, - { url = "https://files.pythonhosted.org/packages/e3/2b/a35a6d7589d21f44cea7d0a98de5ddcbb3d421b2622a5c96b1edf18707c3/numpy-2.4.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:e892aff75639bbef0d2a2cfd55535510df26ff92f63c92cd84ef8d4ba5a5557f", size = 18362959 }, - { url = "https://files.pythonhosted.org/packages/64/c9/d52ec581f2390e0f5f85cbfd80fb83d965fc15e9f0e1aec2195faa142cde/numpy-2.4.4-cp314-cp314-win32.whl", hash = "sha256:1378871da56ca8943c2ba674530924bb8ca40cd228358a3b5f302ad60cf875fc", size = 6008768 }, - { url = "https://files.pythonhosted.org/packages/fa/22/4cc31a62a6c7b74a8730e31a4274c5dc80e005751e277a2ce38e675e4923/numpy-2.4.4-cp314-cp314-win_amd64.whl", hash = "sha256:715d1c092715954784bc79e1174fc2a90093dc4dc84ea15eb14dad8abdcdeb74", size = 12449181 }, - { url = "https://files.pythonhosted.org/packages/70/2e/14cda6f4d8e396c612d1bf97f22958e92148801d7e4f110cabebdc0eef4b/numpy-2.4.4-cp314-cp314-win_arm64.whl", hash = "sha256:2c194dd721e54ecad9ad387c1d35e63dce5c4450c6dc7dd5611283dda239aabb", size = 10496035 }, - { url = "https://files.pythonhosted.org/packages/b1/e8/8fed8c8d848d7ecea092dc3469643f9d10bc3a134a815a3b033da1d2039b/numpy-2.4.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:2aa0613a5177c264ff5921051a5719d20095ea586ca88cc802c5c218d1c67d3e", size = 14824958 }, - { url = "https://files.pythonhosted.org/packages/05/1a/d8007a5138c179c2bf33ef44503e83d70434d2642877ee8fbb230e7c0548/numpy-2.4.4-cp314-cp314t-macosx_14_0_arm64.whl", hash = "sha256:42c16925aa5a02362f986765f9ebabf20de75cdefdca827d14315c568dcab113", size = 5330020 }, - { url = "https://files.pythonhosted.org/packages/99/64/ffb99ac6ae93faf117bcbd5c7ba48a7f45364a33e8e458545d3633615dda/numpy-2.4.4-cp314-cp314t-macosx_14_0_x86_64.whl", hash = "sha256:874f200b2a981c647340f841730fc3a2b54c9d940566a3c4149099591e2c4c3d", size = 6650758 }, - { url = "https://files.pythonhosted.org/packages/6e/6e/795cc078b78a384052e73b2f6281ff7a700e9bf53bcce2ee579d4f6dd879/numpy-2.4.4-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c9b39d38a9bd2ae1becd7eac1303d031c5c110ad31f2b319c6e7d98b135c934d", size = 15729948 }, - { url = "https://files.pythonhosted.org/packages/5f/86/2acbda8cc2af5f3d7bfc791192863b9e3e19674da7b5e533fded124d1299/numpy-2.4.4-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b268594bccac7d7cf5844c7732e3f20c50921d94e36d7ec9b79e9857694b1b2f", size = 16679325 }, - { url = "https://files.pythonhosted.org/packages/bc/59/cafd83018f4aa55e0ac6fa92aa066c0a1877b77a615ceff1711c260ffae8/numpy-2.4.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:ac6b31e35612a26483e20750126d30d0941f949426974cace8e6b5c58a3657b0", size = 17084883 }, - { url = "https://files.pythonhosted.org/packages/f0/85/a42548db84e65ece46ab2caea3d3f78b416a47af387fcbb47ec28e660dc2/numpy-2.4.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:8e3ed142f2728df44263aaf5fb1f5b0b99f4070c553a0d7f033be65338329150", size = 18403474 }, - { url = "https://files.pythonhosted.org/packages/ed/ad/483d9e262f4b831000062e5d8a45e342166ec8aaa1195264982bca267e62/numpy-2.4.4-cp314-cp314t-win32.whl", hash = "sha256:dddbbd259598d7240b18c9d87c56a9d2fb3b02fe266f49a7c101532e78c1d871", size = 6155500 }, - { url = "https://files.pythonhosted.org/packages/c7/03/2fc4e14c7bd4ff2964b74ba90ecb8552540b6315f201df70f137faa5c589/numpy-2.4.4-cp314-cp314t-win_amd64.whl", hash = "sha256:a7164afb23be6e37ad90b2f10426149fd75aee07ca55653d2aa41e66c4ef697e", size = 12637755 }, - { url = "https://files.pythonhosted.org/packages/58/78/548fb8e07b1a341746bfbecb32f2c268470f45fa028aacdbd10d9bc73aab/numpy-2.4.4-cp314-cp314t-win_arm64.whl", hash = "sha256:ba203255017337d39f89bdd58417f03c4426f12beed0440cfd933cb15f8669c7", size = 10566643 }, - { url = "https://files.pythonhosted.org/packages/6b/33/8fae8f964a4f63ed528264ddf25d2b683d0b663e3cba26961eb838a7c1bd/numpy-2.4.4-pp311-pypy311_pp73-macosx_10_15_x86_64.whl", hash = "sha256:58c8b5929fcb8287cbd6f0a3fae19c6e03a5c48402ae792962ac465224a629a4", size = 16854491 }, - { url = "https://files.pythonhosted.org/packages/bc/d0/1aabee441380b981cf8cdda3ae7a46aa827d1b5a8cce84d14598bc94d6d9/numpy-2.4.4-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:eea7ac5d2dce4189771cedb559c738a71512768210dc4e4753b107a2048b3d0e", size = 14895830 }, - { url = "https://files.pythonhosted.org/packages/a5/b8/aafb0d1065416894fccf4df6b49ef22b8db045187949545bced89c034b8e/numpy-2.4.4-pp311-pypy311_pp73-macosx_14_0_arm64.whl", hash = "sha256:51fc224f7ca4d92656d5a5eb315f12eb5fe2c97a66249aa7b5f562528a3be38c", size = 5400927 }, - { url = "https://files.pythonhosted.org/packages/d6/77/063baa20b08b431038c7f9ff5435540c7b7265c78cf56012a483019ca72d/numpy-2.4.4-pp311-pypy311_pp73-macosx_14_0_x86_64.whl", hash = "sha256:28a650663f7314afc3e6ec620f44f333c386aad9f6fc472030865dc0ebb26ee3", size = 6715557 }, - { url = "https://files.pythonhosted.org/packages/c7/a8/379542d45a14f149444c5c4c4e7714707239ce9cc1de8c2803958889da14/numpy-2.4.4-pp311-pypy311_pp73-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:19710a9ca9992d7174e9c52f643d4272dcd1558c5f7af7f6f8190f633bd651a7", size = 15804253 }, - { url = "https://files.pythonhosted.org/packages/a2/c8/f0a45426d6d21e7ea3310a15cf90c43a14d9232c31a837702dba437f3373/numpy-2.4.4-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9b2aec6af35c113b05695ebb5749a787acd63cafc83086a05771d1e1cd1e555f", size = 16753552 }, - { url = "https://files.pythonhosted.org/packages/04/74/f4c001f4714c3ad9ce037e18cf2b9c64871a84951eaa0baf683a9ca9301c/numpy-2.4.4-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:f2cf083b324a467e1ab358c105f6cad5ea950f50524668a80c486ff1db24e119", size = 12509075 }, -] - [[package]] name = "opencv-python" version = "4.13.0.92" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "numpy", version = "2.4.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "numpy" }, ] wheels = [ { url = "https://files.pythonhosted.org/packages/fc/6f/5a28fef4c4a382be06afe3938c64cc168223016fa520c5abaf37e8862aa5/opencv_python-4.13.0.92-cp37-abi3-macosx_13_0_arm64.whl", hash = "sha256:caf60c071ec391ba51ed00a4a920f996d0b64e3e46068aac1f646b5de0326a19", size = 46247052 },