Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
55ee9dba
Commit
55ee9dba
authored
Dec 01, 2013
by
Davis King
Browse files
Added flip_image_dataset_left_right(), upsample_image_dataset(), and
rotate_image_dataset().
parent
c1b71795
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
378 additions
and
0 deletions
+378
-0
dlib/image_transforms/interpolation.h
dlib/image_transforms/interpolation.h
+199
-0
dlib/image_transforms/interpolation_abstract.h
dlib/image_transforms/interpolation_abstract.h
+179
-0
No files found.
dlib/image_transforms/interpolation.h
View file @
55ee9dba
...
@@ -989,6 +989,205 @@ namespace dlib
...
@@ -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
<
template
<
...
...
dlib/image_transforms/interpolation_abstract.h
View file @
55ee9dba
...
@@ -482,6 +482,185 @@ namespace dlib
...
@@ -482,6 +482,185 @@ namespace dlib
That is, this function only appends new elements to each of these containers.
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
<
template
<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment