Skip to content

Commit f6e23ca

Browse files
committed
Gave upsample_image_dataset() an option to limit upsampling on really large images.
1 parent 238febc commit f6e23ca

2 files changed

Lines changed: 41 additions & 22 deletions

File tree

dlib/image_transforms/interpolation.h

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "image_pyramid.h"
1111
#include "../simd.h"
1212
#include "../image_processing/full_object_detection.h"
13+
#include <limits>
1314

1415
namespace dlib
1516
{
@@ -1289,7 +1290,8 @@ namespace dlib
12891290
>
12901291
void upsample_image_dataset (
12911292
image_array_type& images,
1292-
std::vector<std::vector<rectangle> >& objects
1293+
std::vector<std::vector<rectangle> >& objects,
1294+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
12931295
)
12941296
{
12951297
// make sure requires clause is not broken
@@ -1304,11 +1306,14 @@ namespace dlib
13041306
pyramid_type pyr;
13051307
for (unsigned long i = 0; i < images.size(); ++i)
13061308
{
1307-
pyramid_up(images[i], temp, pyr);
1308-
swap(temp, images[i]);
1309-
for (unsigned long j = 0; j < objects[i].size(); ++j)
1309+
if (images[i].size() <= max_image_size)
13101310
{
1311-
objects[i][j] = pyr.rect_up(objects[i][j]);
1311+
pyramid_up(images[i], temp, pyr);
1312+
swap(temp, images[i]);
1313+
for (unsigned long j = 0; j < objects[i].size(); ++j)
1314+
{
1315+
objects[i][j] = pyr.rect_up(objects[i][j]);
1316+
}
13121317
}
13131318
}
13141319
}
@@ -1319,7 +1324,8 @@ namespace dlib
13191324
>
13201325
void upsample_image_dataset (
13211326
image_array_type& images,
1322-
std::vector<std::vector<mmod_rect>>& objects
1327+
std::vector<std::vector<mmod_rect>>& objects,
1328+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
13231329
)
13241330
{
13251331
// make sure requires clause is not broken
@@ -1334,11 +1340,14 @@ namespace dlib
13341340
pyramid_type pyr;
13351341
for (unsigned long i = 0; i < images.size(); ++i)
13361342
{
1337-
pyramid_up(images[i], temp, pyr);
1338-
swap(temp, images[i]);
1339-
for (unsigned long j = 0; j < objects[i].size(); ++j)
1343+
if (images[i].size() <= max_image_size)
13401344
{
1341-
objects[i][j].rect = pyr.rect_up(objects[i][j].rect);
1345+
pyramid_up(images[i], temp, pyr);
1346+
swap(temp, images[i]);
1347+
for (unsigned long j = 0; j < objects[i].size(); ++j)
1348+
{
1349+
objects[i][j].rect = pyr.rect_up(objects[i][j].rect);
1350+
}
13421351
}
13431352
}
13441353
}
@@ -1350,7 +1359,8 @@ namespace dlib
13501359
void upsample_image_dataset (
13511360
image_array_type& images,
13521361
std::vector<std::vector<rectangle> >& objects,
1353-
std::vector<std::vector<rectangle> >& objects2
1362+
std::vector<std::vector<rectangle> >& objects2,
1363+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
13541364
)
13551365
{
13561366
// make sure requires clause is not broken
@@ -1367,15 +1377,18 @@ namespace dlib
13671377
pyramid_type pyr;
13681378
for (unsigned long i = 0; i < images.size(); ++i)
13691379
{
1370-
pyramid_up(images[i], temp, pyr);
1371-
swap(temp, images[i]);
1372-
for (unsigned long j = 0; j < objects[i].size(); ++j)
1373-
{
1374-
objects[i][j] = pyr.rect_up(objects[i][j]);
1375-
}
1376-
for (unsigned long j = 0; j < objects2[i].size(); ++j)
1380+
if (images[i].size() <= max_image_size)
13771381
{
1378-
objects2[i][j] = pyr.rect_up(objects2[i][j]);
1382+
pyramid_up(images[i], temp, pyr);
1383+
swap(temp, images[i]);
1384+
for (unsigned long j = 0; j < objects[i].size(); ++j)
1385+
{
1386+
objects[i][j] = pyr.rect_up(objects[i][j]);
1387+
}
1388+
for (unsigned long j = 0; j < objects2[i].size(); ++j)
1389+
{
1390+
objects2[i][j] = pyr.rect_up(objects2[i][j]);
1391+
}
13791392
}
13801393
}
13811394
}

dlib/image_transforms/interpolation_abstract.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ namespace dlib
677677
>
678678
void upsample_image_dataset (
679679
image_array_type& images,
680-
std::vector<std::vector<rectangle> >& objects
680+
std::vector<std::vector<rectangle> >& objects,
681+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
681682
);
682683
/*!
683684
requires
@@ -690,6 +691,7 @@ namespace dlib
690691
pyramid_type. Therefore, #images[i] will contain the larger upsampled
691692
version of images[i]. It also adjusts all the rectangles in objects so that
692693
they still bound the same visual objects in each image.
694+
- Input images already containing more than max_image_size pixels are not upsampled.
693695
- #images.size() == image.size()
694696
- #objects.size() == objects.size()
695697
- for all valid i:
@@ -704,7 +706,8 @@ namespace dlib
704706
>
705707
void upsample_image_dataset (
706708
image_array_type& images,
707-
std::vector<std::vector<mmod_rect>>& objects
709+
std::vector<std::vector<mmod_rect>>& objects,
710+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
708711
);
709712
/*!
710713
requires
@@ -717,6 +720,7 @@ namespace dlib
717720
pyramid_type. Therefore, #images[i] will contain the larger upsampled
718721
version of images[i]. It also adjusts all the rectangles in objects so that
719722
they still bound the same visual objects in each image.
723+
- Input images already containing more than max_image_size pixels are not upsampled.
720724
- #images.size() == image.size()
721725
- #objects.size() == objects.size()
722726
- for all valid i:
@@ -732,7 +736,8 @@ namespace dlib
732736
void upsample_image_dataset (
733737
image_array_type& images,
734738
std::vector<std::vector<rectangle> >& objects,
735-
std::vector<std::vector<rectangle> >& objects2
739+
std::vector<std::vector<rectangle> >& objects2,
740+
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
736741
);
737742
/*!
738743
requires
@@ -746,6 +751,7 @@ namespace dlib
746751
pyramid_type. Therefore, #images[i] will contain the larger upsampled
747752
version of images[i]. It also adjusts all the rectangles in objects and
748753
objects2 so that they still bound the same visual objects in each image.
754+
- Input images already containing more than max_image_size pixels are not upsampled.
749755
- #images.size() == image.size()
750756
- #objects.size() == objects.size()
751757
- #objects2.size() == objects2.size()

0 commit comments

Comments
 (0)