From 552196b01ed1b79e0dafce408ab075693eb1e2d7 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 25 Sep 2011 11:36:36 -0400 Subject: [PATCH] Added missing assert and made minor refinements to spec. --- dlib/image_transforms/label_connected_blobs.h | 10 ++++++++++ dlib/image_transforms/label_connected_blobs_abstract.h | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dlib/image_transforms/label_connected_blobs.h b/dlib/image_transforms/label_connected_blobs.h index 4a77866fc..0fbade6a4 100644 --- a/dlib/image_transforms/label_connected_blobs.h +++ b/dlib/image_transforms/label_connected_blobs.h @@ -120,11 +120,21 @@ namespace dlib label_image_type& label_img ) { + // make sure requires clause is not broken + DLIB_ASSERT(is_same_object(img, label_img) == false, + "\t unsigned long label_connected_blobs()" + << "\n\t The input image and output label image can't be the same object." + ); + + std::stack neighbors; label_img.set_size(img.nr(), img.nc()); assign_all_pixels(label_img, 0); unsigned long next = 1; + if (img.size() == 0) + return 0; + const rectangle area = get_rect(img); std::vector window; diff --git a/dlib/image_transforms/label_connected_blobs_abstract.h b/dlib/image_transforms/label_connected_blobs_abstract.h index 75debd9a0..dac8252fa 100644 --- a/dlib/image_transforms/label_connected_blobs_abstract.h +++ b/dlib/image_transforms/label_connected_blobs_abstract.h @@ -153,6 +153,7 @@ namespace dlib - get_neighbors(point(c,r), neighbors) is a legal expression where neighbors is of type std::vector. - is_connected(img, point(c,r), point(c2,r2)) is a valid expression. + - is_same_object(img, label_img) == false ensures - This function labels each of the connected blobs in img with a unique integer label. @@ -175,8 +176,11 @@ namespace dlib - #label_img[r][c] == 0 - else - #label_img[r][c] != 0 - - returns max(array_to_matrix(label_img))+1 - (i.e. returns a number one greater than the maximum blob id number) + - if (img.size() != 0) then + - returns max(array_to_matrix(label_img))+1 + (i.e. returns a number one greater than the maximum blob id number) + - else + - returns 0 - blob labels are contiguous, therefore, the number returned by this function is the number of blobs in the image (including the background blob). - It is guaranteed that is_connected() and is_background() will never be