Commit f6e23cab authored by Davis King's avatar Davis King

Gave upsample_image_dataset() an option to limit upsampling on really large images.

parent 238febcc
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "image_pyramid.h" #include "image_pyramid.h"
#include "../simd.h" #include "../simd.h"
#include "../image_processing/full_object_detection.h" #include "../image_processing/full_object_detection.h"
#include <limits>
namespace dlib namespace dlib
{ {
...@@ -1289,7 +1290,8 @@ namespace dlib ...@@ -1289,7 +1290,8 @@ namespace dlib
> >
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<rectangle> >& objects std::vector<std::vector<rectangle> >& objects,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -1304,11 +1306,14 @@ namespace dlib ...@@ -1304,11 +1306,14 @@ namespace dlib
pyramid_type pyr; pyramid_type pyr;
for (unsigned long i = 0; i < images.size(); ++i) for (unsigned long i = 0; i < images.size(); ++i)
{ {
pyramid_up(images[i], temp, pyr); if (images[i].size() <= max_image_size)
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{ {
objects[i][j] = pyr.rect_up(objects[i][j]); pyramid_up(images[i], temp, pyr);
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = pyr.rect_up(objects[i][j]);
}
} }
} }
} }
...@@ -1319,7 +1324,8 @@ namespace dlib ...@@ -1319,7 +1324,8 @@ namespace dlib
> >
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<mmod_rect>>& objects std::vector<std::vector<mmod_rect>>& objects,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -1334,11 +1340,14 @@ namespace dlib ...@@ -1334,11 +1340,14 @@ namespace dlib
pyramid_type pyr; pyramid_type pyr;
for (unsigned long i = 0; i < images.size(); ++i) for (unsigned long i = 0; i < images.size(); ++i)
{ {
pyramid_up(images[i], temp, pyr); if (images[i].size() <= max_image_size)
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{ {
objects[i][j].rect = pyr.rect_up(objects[i][j].rect); pyramid_up(images[i], temp, pyr);
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j].rect = pyr.rect_up(objects[i][j].rect);
}
} }
} }
} }
...@@ -1350,7 +1359,8 @@ namespace dlib ...@@ -1350,7 +1359,8 @@ namespace dlib
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<rectangle> >& objects, std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2 std::vector<std::vector<rectangle> >& objects2,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -1367,15 +1377,18 @@ namespace dlib ...@@ -1367,15 +1377,18 @@ namespace dlib
pyramid_type pyr; pyramid_type pyr;
for (unsigned long i = 0; i < images.size(); ++i) for (unsigned long i = 0; i < images.size(); ++i)
{ {
pyramid_up(images[i], temp, pyr); if (images[i].size() <= max_image_size)
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = pyr.rect_up(objects[i][j]);
}
for (unsigned long j = 0; j < objects2[i].size(); ++j)
{ {
objects2[i][j] = pyr.rect_up(objects2[i][j]); pyramid_up(images[i], temp, pyr);
swap(temp, images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = pyr.rect_up(objects[i][j]);
}
for (unsigned long j = 0; j < objects2[i].size(); ++j)
{
objects2[i][j] = pyr.rect_up(objects2[i][j]);
}
} }
} }
} }
......
...@@ -677,7 +677,8 @@ namespace dlib ...@@ -677,7 +677,8 @@ namespace dlib
> >
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<rectangle> >& objects std::vector<std::vector<rectangle> >& objects,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
); );
/*! /*!
requires requires
...@@ -690,6 +691,7 @@ namespace dlib ...@@ -690,6 +691,7 @@ namespace dlib
pyramid_type. Therefore, #images[i] will contain the larger upsampled pyramid_type. Therefore, #images[i] will contain the larger upsampled
version of images[i]. It also adjusts all the rectangles in objects so that version of images[i]. It also adjusts all the rectangles in objects so that
they still bound the same visual objects in each image. they still bound the same visual objects in each image.
- Input images already containing more than max_image_size pixels are not upsampled.
- #images.size() == image.size() - #images.size() == image.size()
- #objects.size() == objects.size() - #objects.size() == objects.size()
- for all valid i: - for all valid i:
...@@ -704,7 +706,8 @@ namespace dlib ...@@ -704,7 +706,8 @@ namespace dlib
> >
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<mmod_rect>>& objects std::vector<std::vector<mmod_rect>>& objects,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
); );
/*! /*!
requires requires
...@@ -717,6 +720,7 @@ namespace dlib ...@@ -717,6 +720,7 @@ namespace dlib
pyramid_type. Therefore, #images[i] will contain the larger upsampled pyramid_type. Therefore, #images[i] will contain the larger upsampled
version of images[i]. It also adjusts all the rectangles in objects so that version of images[i]. It also adjusts all the rectangles in objects so that
they still bound the same visual objects in each image. they still bound the same visual objects in each image.
- Input images already containing more than max_image_size pixels are not upsampled.
- #images.size() == image.size() - #images.size() == image.size()
- #objects.size() == objects.size() - #objects.size() == objects.size()
- for all valid i: - for all valid i:
...@@ -732,7 +736,8 @@ namespace dlib ...@@ -732,7 +736,8 @@ namespace dlib
void upsample_image_dataset ( void upsample_image_dataset (
image_array_type& images, image_array_type& images,
std::vector<std::vector<rectangle> >& objects, std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2 std::vector<std::vector<rectangle> >& objects2,
unsigned long max_image_size = std::numeric_limits<unsigned long>::max()
); );
/*! /*!
requires requires
...@@ -746,6 +751,7 @@ namespace dlib ...@@ -746,6 +751,7 @@ namespace dlib
pyramid_type. Therefore, #images[i] will contain the larger upsampled pyramid_type. Therefore, #images[i] will contain the larger upsampled
version of images[i]. It also adjusts all the rectangles in objects and version of images[i]. It also adjusts all the rectangles in objects and
objects2 so that they still bound the same visual objects in each image. objects2 so that they still bound the same visual objects in each image.
- Input images already containing more than max_image_size pixels are not upsampled.
- #images.size() == image.size() - #images.size() == image.size()
- #objects.size() == objects.size() - #objects.size() == objects.size()
- #objects2.size() == objects2.size() - #objects2.size() == objects2.size()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment