From 7770225a882147286f358bb8c888782a27eb1466 Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 28 Apr 2016 18:57:15 -0400 Subject: [PATCH] Fixed a bug in gaussian_blur() that caused messed up outputs when big sigma values were used on some pixel types. --- dlib/image_transforms/spatial_filtering.h | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/dlib/image_transforms/spatial_filtering.h b/dlib/image_transforms/spatial_filtering.h index eb0673530..135cbd04f 100644 --- a/dlib/image_transforms/spatial_filtering.h +++ b/dlib/image_transforms/spatial_filtering.h @@ -1233,15 +1233,25 @@ namespace dlib << "\n\t is_same_object(in_img,out_img): " << is_same_object(in_img,out_img) ); - typedef typename pixel_traits::pixel_type>::basic_pixel_type type; - typedef typename promote::type ptype; - - const matrix& filt = create_gaussian_filter(sigma, max_size); - - ptype scale = sum(filt); - scale = scale*scale; - - return spatially_filter_image_separable(in_img, out_img, filt, filt, scale); + if (sigma < 18) + { + typedef typename pixel_traits::pixel_type>::basic_pixel_type type; + typedef typename promote::type ptype; + const matrix& filt = create_gaussian_filter(sigma, max_size); + ptype scale = sum(filt); + scale = scale*scale; + return spatially_filter_image_separable(in_img, out_img, filt, filt, scale); + } + else + { + // For large sigma we need to use a type with a lot of precision to avoid + // numerical problems. So we use double here. + typedef double ptype; + const matrix& filt = create_gaussian_filter(sigma, max_size); + ptype scale = sum(filt); + scale = scale*scale; + return spatially_filter_image_separable(in_img, out_img, filt, filt, scale); + } }