Commit 5d659af7 authored by Davis King's avatar Davis King

Added tile_images()

parent 60333afe
......@@ -6,6 +6,7 @@
#include "draw_abstract.h"
#include "../algs.h"
#include "../pixel.h"
#include "../matrix.h"
#include <cmath>
namespace dlib
......@@ -229,6 +230,51 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template <
typename image_array_type
>
matrix<typename image_array_type::value_type::type> tile_images (
const image_array_type& images
)
{
typedef typename image_array_type::value_type::type T;
if (images.size() == 0)
return matrix<T>();
const unsigned long size_nc = square_root(images.size());
const unsigned long size_nr = (size_nc*(size_nc-1)>=images.size())? size_nc-1 : size_nc;
// Figure out the size we have to use for each chip in the big main image. We will
// use the largest dimensions seen across all the chips.
long nr = 0;
long nc = 0;
for (unsigned long i = 0; i < images.size(); ++i)
{
nr = std::max(images[i].nr(), nr);
nc = std::max(images[i].nc(), nc);
}
matrix<T> temp(size_nr*nr, size_nc*nc);
T background_color;
assign_pixel(background_color, 0);
temp = background_color;
unsigned long idx = 0;
for (long r = 0; r < size_nr; ++r)
{
for (long c = 0; c < size_nc; ++c)
{
if (idx < images.size())
{
set_subm(temp, r*nr, c*nc, nr, nc) = mat(images[idx]);
}
++idx;
}
}
return temp;
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -3,6 +3,7 @@
#undef DLIB_DRAW_IMAGe_ABSTRACT
#ifdef DLIB_DRAW_IMAGe_ABSTRACT
#include "../matrix.h"
namespace dlib
{
......@@ -94,6 +95,24 @@ namespace dlib
- fills the area defined by rect in the given image with the given pixel value.
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_array_type
>
matrix<typename image_array_type::value_type::type> tile_images (
const image_array_type& images
);
/*!
requires
- image_array_type is a dlib::array of array2d objects, each containing pixels
with a pixel_traits definition or any type with a compatible interface.
ensures
- This function takes the given images and tiles them into a single large
square image and returns this new big tiled image. Therefore, it is a useful
method to visualize many small images at once.
!*/
// ----------------------------------------------------------------------------------------
}
......
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