Add imlib mask_ellipse.

This commit is contained in:
iabdalkader 2016-09-08 03:12:14 +02:00
parent 9153325c06
commit 627d81f569
4 changed files with 31 additions and 0 deletions

View File

@ -854,6 +854,23 @@ void imlib_histeq(image_t *img)
fb_free();
}
void imlib_mask_ellipse(image_t *img)
{
int h = img->w/2;
int v = img->h/2;
int a = h * h;
int b = v * v;
uint8_t *pixels = img->pixels;
for (int y=0; y<img->h; y++) {
for (int x=0; x<img->w; x++) {
if ((((x-h)*(x-h)*100) / a + ((y-v)*(y-v)*100) / b) > 100) {
pixels[y*img->w+x] = 0;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
int imlib_image_mean(image_t *src)

View File

@ -451,6 +451,7 @@ void imlib_mean_filter(image_t *img, const int ksize);
void imlib_mode_filter(image_t *img, const int ksize);
void imlib_median_filter(image_t *img, const int ksize, const int percentile);
void imlib_histeq(image_t *img);
void imlib_mask_ellipse(image_t *img);
/* Color Tracking */
array_t *imlib_find_blobs(image_t *img,

View File

@ -866,6 +866,16 @@ static mp_obj_t py_image_histeq(mp_obj_t img_obj)
return img_obj;
}
static mp_obj_t py_image_mask_ellipse(mp_obj_t img_obj)
{
image_t *arg_img = py_image_cobj(img_obj);
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
imlib_mask_ellipse(arg_img);
return img_obj;
}
static bool py_image_find_blobs_f_fun(void *fun_obj, void *img_obj, color_blob_t *cb)
{
mp_obj_t blob_obj[10] = {
@ -1378,6 +1388,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_mean_obj, py_image_mean);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_mode_obj, py_image_mode);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_median_obj, 2, py_image_median);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_histeq_obj, py_image_histeq);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_mask_ellipse_obj, py_image_mask_ellipse);
/* Color Tracking */
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_find_blobs_obj, 2, py_image_find_blobs);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_find_markers_obj, 2, py_image_find_markers);
@ -1440,6 +1451,7 @@ static const mp_map_elem_t locals_dict_table[] = {
{MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&py_image_mode_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_median), (mp_obj_t)&py_image_median_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_histeq), (mp_obj_t)&py_image_histeq_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_mask_ellipse), (mp_obj_t)&py_image_mask_ellipse_obj},
/* Color Tracking */
{MP_OBJ_NEW_QSTR(MP_QSTR_find_blobs), (mp_obj_t)&py_image_find_blobs_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_find_markers), (mp_obj_t)&py_image_find_markers_obj},

View File

@ -74,6 +74,7 @@ Q(kp_desc)
Q(lbp_desc)
Q(Cascade)
Q(histeq)
Q(mask_ellipse)
Q(find_features)
Q(find_keypoints)
Q(find_lbp)