diff --git a/src/image.c b/src/image.c index 52093285..2811cb37 100644 --- a/src/image.c +++ b/src/image.c @@ -494,6 +494,16 @@ image grayscale_image(image im) return gray; } +image threshold_image(image im, float thresh) +{ + int i; + image t = make_image(im.w, im.h, im.c); + for(i = 0; i < im.w*im.h*im.c; ++i){ + t.data[i] = im.data[i]>0 ? 1 : 0; + } + return t; +} + image blend_image(image fore, image back, float alpha) { assert(fore.w == back.w && fore.h == back.h && fore.c == back.c); diff --git a/src/image.h b/src/image.h index 27dc62a7..e16d2854 100644 --- a/src/image.h +++ b/src/image.h @@ -35,7 +35,9 @@ void saturate_exposure_image(image im, float sat, float exposure); void hsv_to_rgb(image im); void rgbgr_image(image im); void constrain_image(image im); + image grayscale_image(image im); +image threshold_image(image im, float thresh); image collapse_image_layers(image source, int border); image collapse_images_horz(image *ims, int n); diff --git a/src/writing.c b/src/writing.c index 7c23db12..02d3fcce 100644 --- a/src/writing.c +++ b/src/writing.c @@ -102,6 +102,10 @@ void test_writing(char *cfgfile, char *weightfile, char *outfile) printf("%s: Predicted in %f seconds.\n", filename, sec(clock()-time)); image pred = get_network_image(net); + image t = threshold_image(pred, .2); + free_image(pred); + pred = t; + if (outfile) { printf("Save image as %s.png (shape: %d %d)\n", outfile, pred.w, pred.h); save_image(pred, outfile);