From 70ea77c044f5792eaf4f233a92487826db7d08d4 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 10 Feb 2024 11:24:57 -0800 Subject: [PATCH] imlib: Add ksize helper. --- src/omv/imlib/binary.c | 4 ++-- src/omv/imlib/imlib.c | 4 ++++ src/omv/imlib/imlib.h | 2 ++ src/omv/modules/py_helper.c | 4 ---- src/omv/modules/py_helper.h | 1 - src/omv/modules/py_image.c | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/omv/imlib/binary.c b/src/omv/imlib/binary.c index d589b775a..3916e0811 100644 --- a/src/omv/imlib/binary.c +++ b/src/omv/imlib/binary.c @@ -906,13 +906,13 @@ void imlib_dilate(image_t *img, int ksize, int threshold, image_t *mask) { } void imlib_open(image_t *img, int ksize, int threshold, image_t *mask) { - imlib_erode(img, ksize, (((ksize * 2) + 1) * ((ksize * 2) + 1)) - 1 - threshold, mask); + imlib_erode(img, ksize, imlib_ksize_to_n(ksize) - 1 - threshold, mask); imlib_dilate(img, ksize, 0 + threshold, mask); } void imlib_close(image_t *img, int ksize, int threshold, image_t *mask) { imlib_dilate(img, ksize, 0 + threshold, mask); - imlib_erode(img, ksize, (((ksize * 2) + 1) * ((ksize * 2) + 1)) - 1 - threshold, mask); + imlib_erode(img, ksize, imlib_ksize_to_n(ksize) - 1 - threshold, mask); } void imlib_top_hat(image_t *img, int ksize, int threshold, image_t *mask) { diff --git a/src/omv/imlib/imlib.c b/src/omv/imlib/imlib.c index 08c681c87..c1509f167 100644 --- a/src/omv/imlib/imlib.c +++ b/src/omv/imlib/imlib.c @@ -34,6 +34,10 @@ void imlib_deinit_all() { #endif } +int imlib_ksize_to_n(int ksize) { + return ((ksize * 2) + 1) * ((ksize * 2) + 1); +} + ///////////////// // Point Stuff // ///////////////// diff --git a/src/omv/imlib/imlib.h b/src/omv/imlib/imlib.h index 89bee8b30..0b1058091 100644 --- a/src/omv/imlib/imlib.h +++ b/src/omv/imlib/imlib.h @@ -96,6 +96,8 @@ #define IM_DEG2RAD(x) (((x) * M_PI) / 180) #define IM_RAD2DEG(x) (((x) * 180) / M_PI) +int imlib_ksize_to_n(int ksize); + ///////////////// // Point Stuff // ///////////////// diff --git a/src/omv/modules/py_helper.c b/src/omv/modules/py_helper.c index 34e99d047..6a52ba42d 100644 --- a/src/omv/modules/py_helper.c +++ b/src/omv/modules/py_helper.c @@ -441,10 +441,6 @@ int py_helper_arg_to_ksize(const mp_obj_t arg) { return ksize; } -int py_helper_ksize_to_n(int ksize) { - return ((ksize * 2) + 1) * ((ksize * 2) + 1); -} - mp_obj_t py_helper_keyword_object(uint n_args, const mp_obj_t *args, uint arg_index, mp_map_t *kw_args, mp_obj_t kw, mp_obj_t default_val) { mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP); diff --git a/src/omv/modules/py_helper.h b/src/omv/modules/py_helper.h index 1726c8414..cc57bda71 100644 --- a/src/omv/modules/py_helper.h +++ b/src/omv/modules/py_helper.h @@ -58,7 +58,6 @@ void py_helper_arg_to_thresholds(const mp_obj_t arg, list_t *thresholds); void py_helper_keyword_thresholds(uint n_args, const mp_obj_t *args, uint arg_index, mp_map_t *kw_args, list_t *thresholds); int py_helper_arg_to_ksize(const mp_obj_t arg); -int py_helper_ksize_to_n(int ksize); mp_obj_t py_helper_keyword_object(uint n_args, const mp_obj_t *args, uint arg_index, mp_map_t *kw_args, mp_obj_t kw, mp_obj_t default_val); const uint16_t *py_helper_keyword_color_palette(uint n_args, const mp_obj_t *args, diff --git a/src/omv/modules/py_image.c b/src/omv/modules/py_image.c index 78ef5b88e..ea4e950c1 100644 --- a/src/omv/modules/py_image.c +++ b/src/omv/modules/py_image.c @@ -2123,7 +2123,7 @@ STATIC mp_obj_t py_image_erode(uint n_args, const mp_obj_t *args, mp_map_t *kw_a py_helper_arg_to_ksize(args[1]); int arg_threshold = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), - py_helper_ksize_to_n(arg_ksize) - 1); + imlib_ksize_to_n(arg_ksize) - 1); image_t *arg_msk = py_helper_keyword_to_image(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_mask), NULL); @@ -2607,7 +2607,7 @@ STATIC mp_obj_t py_image_morph(uint n_args, const mp_obj_t *args, mp_map_t *kw_a int arg_ksize = py_helper_arg_to_ksize(args[1]); - int n = py_helper_ksize_to_n(arg_ksize); + int n = imlib_ksize_to_n(arg_ksize); mp_obj_t *krn; mp_obj_get_array_fixed_n(args[2], n, &krn);