Merge pull request #799 from kwagyeman/kwabena/get_histogram_with_diff

Add image diff ability to get_histogram
This commit is contained in:
Ibrahim Abd Elkader 2020-05-13 21:12:46 +02:00 committed by GitHub
commit d81f58569b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 64 deletions

View File

@ -1344,7 +1344,7 @@ void imlib_rotation_corr(image_t *img, float x_rotation, float y_rotation,
float zoom, float fov, float *corners); float zoom, float fov, float *corners);
// Statistics // Statistics
void imlib_get_similarity(image_t *img, const char *path, image_t *other, int scalar, float *avg, float *std, float *min, float *max); void imlib_get_similarity(image_t *img, const char *path, image_t *other, int scalar, float *avg, float *std, float *min, float *max);
void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_t *thresholds, bool invert); void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_t *thresholds, bool invert, image_t *other);
void imlib_get_percentile(percentile_t *out, image_bpp_t bpp, histogram_t *ptr, float percentile); void imlib_get_percentile(percentile_t *out, image_bpp_t bpp, histogram_t *ptr, float percentile);
void imlib_get_threshold(threshold_t *out, image_bpp_t bpp, histogram_t *ptr); void imlib_get_threshold(threshold_t *out, image_bpp_t bpp, histogram_t *ptr);
void imlib_get_statistics(statistics_t *out, image_bpp_t bpp, histogram_t *ptr); void imlib_get_statistics(statistics_t *out, image_bpp_t bpp, histogram_t *ptr);

View File

@ -202,7 +202,7 @@ void imlib_remove_shadows(image_t *img, const char *path, image_t *other, int sc
h.LBins = fb_alloc(h.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); h.LBins = fb_alloc(h.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
h.ABins = fb_alloc(h.ABinCount * sizeof(float), FB_ALLOC_NO_HINT); h.ABins = fb_alloc(h.ABinCount * sizeof(float), FB_ALLOC_NO_HINT);
h.BBins = fb_alloc(h.BBinCount * sizeof(float), FB_ALLOC_NO_HINT); h.BBins = fb_alloc(h.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
imlib_get_histogram(&h, &temp_image, &r, NULL, false); imlib_get_histogram(&h, &temp_image, &r, NULL, false, NULL);
statistics_t s; statistics_t s;
imlib_get_statistics(&s, temp_image.bpp, &h); imlib_get_statistics(&s, temp_image.bpp, &h);

View File

@ -146,7 +146,7 @@ void imlib_get_similarity(image_t *img, const char *path, image_t *other, int sc
} }
#endif //IMLIB_ENABLE_GET_SIMILARITY #endif //IMLIB_ENABLE_GET_SIMILARITY
void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_t *thresholds, bool invert) void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_t *thresholds, bool invert, image_t *other)
{ {
switch(ptr->bpp) { switch(ptr->bpp) {
case IMAGE_BPP_BINARY: { case IMAGE_BPP_BINARY: {
@ -157,16 +157,27 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
if ((!thresholds) || (!list_size(thresholds))) { if ((!thresholds) || (!list_size(thresholds))) {
// Fast histogram code when no color thresholds list... // Fast histogram code when no color thresholds list...
if (!other) {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x);
((uint32_t *) out->LBins)[fast_floorf((pixel - COLOR_BINARY_MIN) * mult)]++; ((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_BINARY_MIN) * mult)]++; // needs to be roundf
}
}
} else {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x) ^ IMAGE_GET_BINARY_PIXEL_FAST(other_row_ptr, x);
((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_BINARY_MIN) * mult)]++; // needs to be roundf
}
} }
} }
} else { } else {
// Reset pixel count. // Reset pixel count.
pixel_count = 0; pixel_count = 0;
if (!other) {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) { for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data; color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data); iterator_get(thresholds, it, &lnk_data);
@ -176,12 +187,29 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x);
if (COLOR_THRESHOLD_BINARY(pixel, &lnk_data, invert)) { if (COLOR_THRESHOLD_BINARY(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_floorf((pixel - COLOR_BINARY_MIN) * mult)]++; ((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_BINARY_MIN) * mult)]++; // needs to be roundf
pixel_count++; pixel_count++;
} }
} }
} }
} }
} else {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data);
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x) ^ IMAGE_GET_BINARY_PIXEL_FAST(other_row_ptr, x);
if (COLOR_THRESHOLD_BINARY(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_BINARY_MIN) * mult)]++; // needs to be roundf
pixel_count++;
}
}
}
}
}
} }
float pixels = IM_DIV(1, ((float) pixel_count)); float pixels = IM_DIV(1, ((float) pixel_count));
@ -200,16 +228,27 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
if ((!thresholds) || (!list_size(thresholds))) { if ((!thresholds) || (!list_size(thresholds))) {
// Fast histogram code when no color thresholds list... // Fast histogram code when no color thresholds list...
if (!other) {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y); uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x);
((uint32_t *) out->LBins)[fast_floorf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; ((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; // needs to be roundf
}
}
} else {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = abs(IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x) - IMAGE_GET_GRAYSCALE_PIXEL_FAST(other_row_ptr, x));
((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; // needs to be roundf
}
} }
} }
} else { } else {
// Reset pixel count. // Reset pixel count.
pixel_count = 0; pixel_count = 0;
if (!other) {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) { for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data; color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data); iterator_get(thresholds, it, &lnk_data);
@ -219,12 +258,29 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x);
if (COLOR_THRESHOLD_GRAYSCALE(pixel, &lnk_data, invert)) { if (COLOR_THRESHOLD_GRAYSCALE(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_floorf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; ((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; // needs to be roundf
pixel_count++; pixel_count++;
} }
} }
} }
} }
} else {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data);
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = abs(IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x) - IMAGE_GET_GRAYSCALE_PIXEL_FAST(other_row_ptr, x));
if (COLOR_THRESHOLD_GRAYSCALE(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_roundf((pixel - COLOR_GRAYSCALE_MIN) * mult)]++; // needs to be roundf
pixel_count++;
}
}
}
}
}
} }
float pixels = IM_DIV(1, ((float) pixel_count)); float pixels = IM_DIV(1, ((float) pixel_count));
@ -247,18 +303,35 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
if ((!thresholds) || (!list_size(thresholds))) { if ((!thresholds) || (!list_size(thresholds))) {
// Fast histogram code when no color thresholds list... // Fast histogram code when no color thresholds list...
if (!other) {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x);
((uint32_t *) out->LBins)[fast_floorf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; ((uint32_t *) out->LBins)[fast_roundf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; // needs to be roundf
((uint32_t *) out->ABins)[fast_floorf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; ((uint32_t *) out->ABins)[fast_roundf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; // needs to be roundf
((uint32_t *) out->BBins)[fast_floorf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; ((uint32_t *) out->BBins)[fast_roundf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; // needs to be roundf
}
}
} else {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x), other_pixel = IMAGE_GET_RGB565_PIXEL_FAST(other_row_ptr, x);
int r = abs(COLOR_RGB565_TO_R5(pixel) - COLOR_RGB565_TO_R5(other_pixel));
int g = abs(COLOR_RGB565_TO_G6(pixel) - COLOR_RGB565_TO_G6(other_pixel));
int b = abs(COLOR_RGB565_TO_B5(pixel) - COLOR_RGB565_TO_B5(other_pixel));
pixel = COLOR_R5_G6_B5_TO_RGB565(r, g, b);
((uint32_t *) out->LBins)[fast_roundf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; // needs to be roundf
((uint32_t *) out->ABins)[fast_roundf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; // needs to be roundf
((uint32_t *) out->BBins)[fast_roundf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; // needs to be roundf
}
} }
} }
} else { } else {
// Reset pixel count. // Reset pixel count.
pixel_count = 0; pixel_count = 0;
if (!other) {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) { for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data; color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data); iterator_get(thresholds, it, &lnk_data);
@ -268,14 +341,37 @@ void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi, list_
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x); int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x);
if (COLOR_THRESHOLD_RGB565(pixel, &lnk_data, invert)) { if (COLOR_THRESHOLD_RGB565(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_floorf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; ((uint32_t *) out->LBins)[fast_roundf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; // needs to be roundf
((uint32_t *) out->ABins)[fast_floorf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; ((uint32_t *) out->ABins)[fast_roundf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; // needs to be roundf
((uint32_t *) out->BBins)[fast_floorf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; ((uint32_t *) out->BBins)[fast_roundf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; // needs to be roundf
pixel_count++; pixel_count++;
} }
} }
} }
} }
} else {
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data);
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y), *other_row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(other, y);
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x), other_pixel = IMAGE_GET_RGB565_PIXEL_FAST(other_row_ptr, x);
int r = abs(COLOR_RGB565_TO_R5(pixel) - COLOR_RGB565_TO_R5(other_pixel));
int g = abs(COLOR_RGB565_TO_G6(pixel) - COLOR_RGB565_TO_G6(other_pixel));
int b = abs(COLOR_RGB565_TO_B5(pixel) - COLOR_RGB565_TO_B5(other_pixel));
pixel = COLOR_R5_G6_B5_TO_RGB565(r, g, b);
if (COLOR_THRESHOLD_RGB565(pixel, &lnk_data, invert)) {
((uint32_t *) out->LBins)[fast_roundf((COLOR_RGB565_TO_L(pixel) - COLOR_L_MIN) * l_mult)]++; // needs to be roundf
((uint32_t *) out->ABins)[fast_roundf((COLOR_RGB565_TO_A(pixel) - COLOR_A_MIN) * a_mult)]++; // needs to be roundf
((uint32_t *) out->BBins)[fast_roundf((COLOR_RGB565_TO_B(pixel) - COLOR_B_MIN) * b_mult)]++; // needs to be roundf
pixel_count++;
}
}
}
}
}
} }
float pixels = IM_DIV(1, ((float) pixel_count)); float pixels = IM_DIV(1, ((float) pixel_count));

View File

@ -4063,6 +4063,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
list_init(&thresholds, sizeof(color_thresholds_list_lnk_data_t)); list_init(&thresholds, sizeof(color_thresholds_list_lnk_data_t));
py_helper_keyword_thresholds(n_args, args, 1, kw_args, &thresholds); py_helper_keyword_thresholds(n_args, args, 1, kw_args, &thresholds);
bool invert = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_invert), false); bool invert = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_invert), false);
image_t *other = py_helper_keyword_to_image_mutable(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_difference), NULL);
rectangle_t roi; rectangle_t roi;
py_helper_keyword_rectangle_roi(arg_img, n_args, args, 3, kw_args, &roi); py_helper_keyword_rectangle_roi(arg_img, n_args, args, 3, kw_args, &roi);
@ -4081,7 +4082,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = NULL; hist.ABins = NULL;
hist.BBins = NULL; hist.BBins = NULL;
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }
@ -4097,7 +4098,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = NULL; hist.ABins = NULL;
hist.BBins = NULL; hist.BBins = NULL;
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }
@ -4121,7 +4122,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = fb_alloc(hist.ABinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.ABins = fb_alloc(hist.ABinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }
@ -4164,6 +4165,7 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
list_init(&thresholds, sizeof(color_thresholds_list_lnk_data_t)); list_init(&thresholds, sizeof(color_thresholds_list_lnk_data_t));
py_helper_keyword_thresholds(n_args, args, 1, kw_args, &thresholds); py_helper_keyword_thresholds(n_args, args, 1, kw_args, &thresholds);
bool invert = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_invert), false); bool invert = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_invert), false);
image_t *other = py_helper_keyword_to_image_mutable(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_difference), NULL);
rectangle_t roi; rectangle_t roi;
py_helper_keyword_rectangle_roi(arg_img, n_args, args, 3, kw_args, &roi); py_helper_keyword_rectangle_roi(arg_img, n_args, args, 3, kw_args, &roi);
@ -4182,7 +4184,7 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = NULL; hist.ABins = NULL;
hist.BBins = NULL; hist.BBins = NULL;
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }
@ -4198,7 +4200,7 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = NULL; hist.ABins = NULL;
hist.BBins = NULL; hist.BBins = NULL;
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }
@ -4222,7 +4224,7 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.LBins = fb_alloc(hist.LBinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.ABins = fb_alloc(hist.ABinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.ABins = fb_alloc(hist.ABinCount * sizeof(float), FB_ALLOC_NO_HINT);
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT); hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert); imlib_get_histogram(&hist, arg_img, &roi, &thresholds, invert, other);
list_free(&thresholds); list_free(&thresholds);
break; break;
} }