Commit 0da136b0 authored by Davis King's avatar Davis King

Added an overload of draw_image() that's useful for drawing images

and doing interpolation at the same time.
parent 6643cbb8
...@@ -695,6 +695,37 @@ namespace dlib ...@@ -695,6 +695,37 @@ namespace dlib
} }
} }
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void draw_image (
const canvas& c,
const rectangle& rect,
const image_type& img,
const rectangle& area_ = rectangle(std::numeric_limits<long>::min(), std::numeric_limits<long>::min(),
std::numeric_limits<long>::max(), std::numeric_limits<long>::max())
)
{
const rectangle area = c.intersect(rect).intersect(area_);
if (area.is_empty() || img.size() == 0)
return;
const matrix<long,1> x = matrix_cast<long>(round(linspace(0, img.nc()-1, rect.width())));
const matrix<long,1> y = matrix_cast<long>(round(linspace(0, img.nr()-1, rect.height())));
for (long row = area.top(); row <= area.bottom(); ++row)
{
const long r = y(row-rect.top());
long cc = area.left() - rect.left();
for (long col = area.left(); col <= area.right(); ++col)
{
assign_pixel(c[row-c.top()][col-c.left()], img[r][x(cc++)]);
}
}
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename pixel_type> template <typename pixel_type>
......
...@@ -240,6 +240,33 @@ namespace dlib ...@@ -240,6 +240,33 @@ namespace dlib
- only draws the part of the image that overlaps with the area rectangle - only draws the part of the image that overlaps with the area rectangle
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void draw_image (
const canvas& c,
const rectangle& rect,
const image_type& img,
const rectangle& area = rectangle(-infinity,-infinity,infinity,infinity)
);
/*!
requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- draws the given image object onto the canvas such that the upper left corner
of the image will appear at the point rect.tl_corner() in the canvas's window
and the lower right corner of the image will appear at rect.br_corner() in
the canvas's window. (note that the upper left corner of the image is
assumed to be the pixel image[0][0] and the lower right corner of the image
is assumed to be image[image.nr()-1][image.nc()-1])
- only draws the part of the image that overlaps with the area rectangle
- Uses nearest neighbor interpolation when the given rect isn't the same size
as the input image.
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < 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