Commit 55ee9dba authored by Davis King's avatar Davis King

Added flip_image_dataset_left_right(), upsample_image_dataset(), and

rotate_image_dataset().
parent c1b71795
......@@ -989,6 +989,205 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template <typename image_type>
void flip_image_dataset_left_right (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size(),
"\t void flip_image_dataset_left_right()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
);
image_type temp;
for (unsigned long i = 0; i < images.size(); ++i)
{
flip_image_left_right(images[i], temp);
temp.swap(images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = impl::flip_rect_left_right(objects[i][j], get_rect(images[i]));
}
}
}
// ----------------------------------------------------------------------------------------
template <typename image_type>
void flip_image_dataset_left_right (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size() &&
images.size() == objects2.size(),
"\t void flip_image_dataset_left_right()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
<< "\n\t objects2.size(): " << objects2.size()
);
image_type temp;
for (unsigned long i = 0; i < images.size(); ++i)
{
flip_image_left_right(images[i], temp);
temp.swap(images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = impl::flip_rect_left_right(objects[i][j], get_rect(images[i]));
}
for (unsigned long j = 0; j < objects2[i].size(); ++j)
{
objects2[i][j] = impl::flip_rect_left_right(objects2[i][j], get_rect(images[i]));
}
}
}
// ----------------------------------------------------------------------------------------
template <
typename pyramid_type,
typename image_type
>
void upsample_image_dataset (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size(),
"\t void upsample_image_dataset()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
);
image_type temp;
pyramid_type pyr;
for (unsigned long i = 0; i < images.size(); ++i)
{
pyramid_up(images[i], temp, pyr);
temp.swap(images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
objects[i][j] = pyr.rect_up(objects[i][j]);
}
}
}
template <
typename pyramid_type,
typename image_type
>
void upsample_image_dataset (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size() &&
images.size() == objects2.size(),
"\t void upsample_image_dataset()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
<< "\n\t objects2.size(): " << objects2.size()
);
image_type temp;
pyramid_type pyr;
for (unsigned long i = 0; i < images.size(); ++i)
{
pyramid_up(images[i], temp, pyr);
temp.swap(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]);
}
}
}
// ----------------------------------------------------------------------------------------
template <typename image_type>
void rotate_image_dataset (
double angle,
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size(),
"\t void rotate_image_dataset()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
);
image_type temp;
for (unsigned long i = 0; i < images.size(); ++i)
{
const point_transform_affine tran = inv(rotate_image(images[i], temp, angle));
temp.swap(images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
const rectangle rect = objects[i][j];
objects[i][j] = centered_rect(tran(center(rect)), rect.width(), rect.height());
}
}
}
template <typename image_type>
void rotate_image_dataset (
double angle,
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size() &&
images.size() == objects2.size(),
"\t void rotate_image_dataset()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
<< "\n\t objects2.size(): " << objects2.size()
);
image_type temp;
for (unsigned long i = 0; i < images.size(); ++i)
{
const point_transform_affine tran = inv(rotate_image(images[i], temp, angle));
temp.swap(images[i]);
for (unsigned long j = 0; j < objects[i].size(); ++j)
{
const rectangle rect = objects[i][j];
objects[i][j] = centered_rect(tran(center(rect)), rect.width(), rect.height());
}
for (unsigned long j = 0; j < objects2[i].size(); ++j)
{
const rectangle rect = objects2[i][j];
objects2[i][j] = centered_rect(tran(center(rect)), rect.width(), rect.height());
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
......
......@@ -482,6 +482,185 @@ namespace dlib
That is, this function only appends new elements to each of these containers.
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void flip_image_dataset_left_right (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
ensures
- This function replaces each image in images with the left/right flipped
version of the image. Therefore, #images[i] will contain the left/right
flipped version of images[i]. It also flips all the rectangles in objects so
that they still bound the same visual objects in each image.
- #images.size() == image.size()
- #objects.size() == objects.size()
- for all valid i:
#objects[i].size() == objects[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void flip_image_dataset_left_right (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
- images.size() == objects2.size()
ensures
- This function replaces each image in images with the left/right flipped
version of the image. Therefore, #images[i] will contain the left/right
flipped version of images[i]. It also flips all the rectangles in objects
and objects2 so that they still bound the same visual objects in each image.
- #images.size() == image.size()
- #objects.size() == objects.size()
- #objects2.size() == objects2.size()
- for all valid i:
#objects[i].size() == objects[i].size()
- for all valid i:
#objects2[i].size() == objects2[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <
typename pyramid_type,
typename image_type
>
void upsample_image_dataset (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
ensures
- This function replaces each image in images with an upsampled version of that
image. Each image is upsampled using pyramid_up() and the given
pyramid_type. Therefore, #images[i] will contain the larger upsampled
version of images[i]. It also adjusts all the rectangles in objects so that
they still bound the same visual objects in each image.
- #images.size() == image.size()
- #objects.size() == objects.size()
- for all valid i:
#objects[i].size() == objects[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <
typename pyramid_type,
typename image_type
>
void upsample_image_dataset (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
- images.size() == objects2.size()
ensures
- This function replaces each image in images with an upsampled version of that
image. Each image is upsampled using pyramid_up() and the given
pyramid_type. Therefore, #images[i] will contain the larger upsampled
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.
- #images.size() == image.size()
- #objects.size() == objects.size()
- #objects2.size() == objects2.size()
- for all valid i:
#objects[i].size() == objects[i].size()
- for all valid i:
#objects2[i].size() == objects2[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <typename image_type>
void rotate_image_dataset (
double angle,
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
ensures
- This function replaces each image in images with a rotated version of that
image. In particular, each image is rotated using
rotate_image(original,rotated,angle). Therefore, the images are rotated
angle radians counter clockwise around their centers. That is, #images[i]
will contain the rotated version of images[i]. It also adjusts all
the rectangles in objects so that they still bound the same visual objects in
each image.
- All the rectangles will still have the same sizes and aspect ratios after
rotation. They will simply have had their positions adjusted so they still
fall on the same objects.
- #images.size() == image.size()
- #objects.size() == objects.size()
- for all valid i:
#objects[i].size() == objects[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <typename image_type>
void rotate_image_dataset (
double angle,
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects,
std::vector<std::vector<rectangle> >& objects2
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
- images.size() == objects2.size()
ensures
- This function replaces each image in images with a rotated version of that
image. In particular, each image is rotated using
rotate_image(original,rotated,angle). Therefore, the images are rotated
angle radians counter clockwise around their centers. That is, #images[i]
will contain the rotated 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.
- All the rectangles will still have the same sizes and aspect ratios after
rotation. They will simply have had their positions adjusted so they still
fall on the same objects.
- #images.size() == image.size()
- #objects.size() == objects.size()
- #objects2.size() == objects2.size()
- for all valid i:
#objects[i].size() == objects[i].size()
- for all valid i:
#objects2[i].size() == objects2[i].size()
!*/
// ----------------------------------------------------------------------------------------
template <
......
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