Commit a56bab46 authored by Davis King's avatar Davis King

Made assign_image() and assign_image_scaled() a little more general. Now

they can use source images which are matrices in addition to array2d objects.
This change also enables the image_window to display matrices.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404244
parent 9f17b8cb
......@@ -16,33 +16,45 @@ namespace dlib
typename dest_image_type,
typename src_image_type
>
void assign_image (
void impl_assign_image (
dest_image_type& dest,
const src_image_type& src
)
{
// check for the case where dest is the same object as src
if (is_same_object(dest,src))
return;
dest.set_size(src.nr(),src.nc());
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
assign_pixel(dest[r][c], src[r][c]);
assign_pixel(dest[r][c], src(r,c));
}
}
}
template <
typename dest_image_type,
typename src_image_type
>
void assign_image (
dest_image_type& dest,
const src_image_type& src
)
{
// check for the case where dest is the same object as src
if (is_same_object(dest,src))
return;
impl_assign_image(dest, array_to_matrix(src));
}
// ----------------------------------------------------------------------------------------
template <
typename dest_image_type,
typename src_image_type
>
void assign_image_scaled (
void impl_assign_image_scaled (
dest_image_type& dest,
const src_image_type& src,
const double thresh = 4
......@@ -70,7 +82,7 @@ namespace dlib
if (src.size() == 1)
{
assign_pixel(dest[0][0], src[0][0]);
assign_pixel(dest[0][0], src(0,0));
return;
}
......@@ -80,7 +92,7 @@ namespace dlib
{
for (long c = 0; c < src.nc(); ++c)
{
rs.add(get_pixel_intensity(src[r][c]));
rs.add(get_pixel_intensity(src(r,c)));
}
}
typedef typename pixel_traits<typename src_image_type::type>::basic_pixel_type spix_type;
......@@ -92,7 +104,7 @@ namespace dlib
if (pixel_traits<typename dest_image_type::type>::max() >= rs.max() &&
pixel_traits<typename dest_image_type::type>::min() <= rs.min() )
{
assign_image(dest, src);
impl_assign_image(dest, src);
return;
}
}
......@@ -112,13 +124,30 @@ namespace dlib
{
for (long c = 0; c < src.nc(); ++c)
{
const double val = get_pixel_intensity(src[r][c]) - lower;
const double val = get_pixel_intensity(src(r,c)) - lower;
assign_pixel(dest[r][c], scale*val + dest_min);
}
}
}
template <
typename dest_image_type,
typename src_image_type
>
void assign_image_scaled (
dest_image_type& dest,
const src_image_type& src,
const double thresh = 4
)
{
// check for the case where dest is the same object as src
if (is_same_object(dest,src))
return;
impl_assign_image_scaled(dest, array_to_matrix(src),thresh);
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -20,7 +20,8 @@ namespace dlib
);
/*!
requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename src_image_type::type> is defined
- pixel_traits<typename dest_image_type::type> is defined
......@@ -45,7 +46,8 @@ namespace dlib
);
/*!
requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename src_image_type::type> is defined
- pixel_traits<typename dest_image_type::type> is defined
......
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