diff --git a/dlib/image_transforms/image_pyramid.h b/dlib/image_transforms/image_pyramid.h index 08bc1e466..ec4ce363a 100644 --- a/dlib/image_transforms/image_pyramid.h +++ b/dlib/image_transforms/image_pyramid.h @@ -988,7 +988,8 @@ namespace dlib const image_type1& img, image_type2& out_img, std::vector& rects, - const unsigned long padding = 10 + const unsigned long padding = 10, + const unsigned long outer_padding = 0 ) { DLIB_ASSERT(!is_same_object(img, out_img)); @@ -1038,14 +1039,15 @@ namespace dlib } height -= padding; // don't add unnecessary padding to the very right side. - set_image_size(out_img,height,img.nc()); + const long width = img.nc(); + set_image_size(out_img,height+outer_padding*2,width+outer_padding*2); assign_all_pixels(out_img, 0); - long y = 0; + long y = outer_padding; size_t i = 0; - while(y < height) + while(y < height+outer_padding) { - rectangle rect = translate_rect(get_rect(pyramid[i]),point(0,y)); + rectangle rect = translate_rect(get_rect(pyramid[i]),point(outer_padding,y)); DLIB_ASSERT(get_rect(out_img).contains(rect)); rects.push_back(rect); auto si = sub_image(out_img, rect); @@ -1056,7 +1058,7 @@ namespace dlib y -= padding; while (i < pyramid.size()) { - point p1(img.nc()-1,y-1); + point p1(outer_padding+width-1,y-1); point p2 = p1 - get_rect(pyramid[i]).br_corner(); rectangle rect(p1,p2); DLIB_ASSERT(get_rect(out_img).contains(rect)); diff --git a/dlib/image_transforms/image_pyramid_abstract.h b/dlib/image_transforms/image_pyramid_abstract.h index 4e4c33d56..a72dddbbe 100644 --- a/dlib/image_transforms/image_pyramid_abstract.h +++ b/dlib/image_transforms/image_pyramid_abstract.h @@ -219,7 +219,8 @@ namespace dlib const image_type1& img, image_type2& out_img, std::vector& rects, - const unsigned long padding = 10 + const unsigned long padding = 10, + const unsigned long outer_padding = 0 ); /*! requires @@ -237,7 +238,8 @@ namespace dlib pyramid levels are generated from pyramid_type's downsampling. The entire resulting pyramid is packed into a single image and stored in out_img. - When packing pyramid levels into out_img, there will be padding pixels of - space between each sub-image. + space between each sub-image. There will also be outer_padding pixels of + padding around the edge of the image. All padding pixels have a value of 0. - The resulting pyramid will be composed of #rects.size() images packed into out_img. Moreover, #rects[i] is the location inside out_img of the i-th pyramid level.