Commit 3714ff54 authored by Davis King's avatar Davis King

Gave the spatially_filter_image routines the ability to add their

results to an output image rather than overwrite the contents
of the output image.
parent cae3da77
......@@ -27,7 +27,8 @@ namespace dlib
out_image_type& out_img,
const matrix_exp<EXP>& filter,
T scale,
bool use_abs = false
bool use_abs = false,
bool add_to = false
)
{
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
......@@ -92,8 +93,15 @@ namespace dlib
}
// save this pixel to the output image
assign_pixel(out_img[r][c], in_img[r][c]);
assign_pixel_intensity(out_img[r][c], temp);
if (add_to == false)
{
assign_pixel(out_img[r][c], in_img[r][c]);
assign_pixel_intensity(out_img[r][c], temp);
}
else
{
assign_pixel(out_img[r][c], temp + get_pixel_intensity(out_img[r][c]));
}
}
}
}
......@@ -127,7 +135,8 @@ namespace dlib
const matrix_exp<EXP1>& row_filter,
const matrix_exp<EXP2>& col_filter,
T scale,
bool use_abs = false
bool use_abs = false,
bool add_to = false
)
{
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
......@@ -213,8 +222,15 @@ namespace dlib
}
// save this pixel to the output image
assign_pixel(out_img[r][c], in_img[r][c]);
assign_pixel_intensity(out_img[r][c], temp);
if (add_to == false)
{
assign_pixel(out_img[r][c], in_img[r][c]);
assign_pixel_intensity(out_img[r][c], temp);
}
else
{
assign_pixel(out_img[r][c], temp + get_pixel_intensity(out_img[r][c]));
}
}
}
}
......
......@@ -22,7 +22,8 @@ namespace dlib
out_image_type& out_img,
const matrix_exp<EXP>& filter,
T scale = 1,
bool use_abs = false
bool use_abs = false,
bool add_to = false
);
/*!
requires
......@@ -41,14 +42,16 @@ namespace dlib
- The intermediate filter computations will be carried out using variables of type EXP::type.
This is whatever scalar type is used inside the filter matrix.
- Pixel values are stored into out_img using the assign_pixel() function and therefore
any applicable color space conversion or value saturation is performed.
any applicable color space conversion or value saturation is performed. Note that if
add_to is true then the filtered output value will be added to out_img rather than
overwriting the original value.
- if (pixel_traits<typename in_image_type::type>::grayscale == false) then
- the pixel values are converted to the HSI color space and the filtering
is done on the intensity channel only.
- if (use_abs == true) then
- pixel values after filtering that are < 0 are converted to their absolute values.
- Pixels close enough to the edge of in_img to not have the filter still fit
inside the image are set to zero.
inside the image are always set to zero.
- #out_img.nc() == in_img.nc()
- #out_img.nr() == in_img.nr()
!*/
......@@ -68,7 +71,8 @@ namespace dlib
const matrix_exp<EXP1>& row_filter,
const matrix_exp<EXP2>& col_filter,
T scale = 1,
bool use_abs = false
bool use_abs = false,
bool add_to = false
);
/*!
requires
......@@ -92,14 +96,16 @@ namespace dlib
- The intermediate filter computations will be carried out using variables of type EXP1::type.
This is whatever scalar type is used inside the row_filter matrix.
- Pixel values are stored into out_img using the assign_pixel() function and therefore
any applicable color space conversion or value saturation is performed.
any applicable color space conversion or value saturation is performed. Note that if
add_to is true then the filtered output value will be added to out_img rather than
overwriting the original value.
- if (pixel_traits<typename in_image_type::type>::grayscale == false) then
- the pixel values are converted to the HSI color space and the filtering
is done on the intensity channel only.
- if (use_abs == true) then
- pixel values after filtering that are < 0 are converted to their absolute values
- Pixels close enough to the edge of in_img to not have the filter still fit
inside the image are set to zero.
inside the image are always set to zero.
- #out_img.nc() == in_img.nc()
- #out_img.nr() == in_img.nr()
!*/
......
......@@ -924,6 +924,23 @@ namespace
DLIB_TEST(img2[2][1] == 0);
DLIB_TEST(img2[2][2] == 0);
DLIB_TEST(img2[2][3] == 0);
assign_all_pixels(img2, 3);
spatially_filter_image_separable(img,img2,rowf,colf,1,true, true);
DLIB_TEST(img2[0][0] == 0);
DLIB_TEST(img2[0][1] == 0);
DLIB_TEST(img2[0][2] == 0);
DLIB_TEST(img2[0][3] == 0);
DLIB_TEST(img2[1][0] == 0);
DLIB_TEST_MSG(img2[1][1] == 9+3, img2[1][1] );
DLIB_TEST(img2[1][2] == 9+3);
DLIB_TEST(img2[1][3] == 0);
DLIB_TEST(img2[2][0] == 0);
DLIB_TEST(img2[2][1] == 0);
DLIB_TEST(img2[2][2] == 0);
DLIB_TEST(img2[2][3] == 0);
}
{
array2d<double> img, img2;
......@@ -941,8 +958,36 @@ namespace
DLIB_TEST(img2[0][3] == 0);
DLIB_TEST(img2[1][0] == 0);
DLIB_TEST((img2[1][1] - -4.5) < 1e-14);
DLIB_TEST((img2[1][2] - -4.5) < 1e-14);
DLIB_TEST(std::abs(img2[1][1] - -4.5) < 1e-14);
DLIB_TEST(std::abs(img2[1][2] - -4.5) < 1e-14);
DLIB_TEST(img2[1][3] == 0);
DLIB_TEST(img2[2][0] == 0);
DLIB_TEST(img2[2][1] == 0);
DLIB_TEST(img2[2][2] == 0);
DLIB_TEST(img2[2][3] == 0);
}
{
array2d<double> img, img2;
img.set_size(3,4);
img2.set_size(3,4);
assign_all_pixels(img2, 8);
matrix<double> filter(3,3);
filter = 1;
assign_all_pixels(img,-1);
spatially_filter_image(img,img2,filter,2, false, true);
DLIB_TEST(img2[0][0] == 0);
DLIB_TEST(img2[0][1] == 0);
DLIB_TEST(img2[0][2] == 0);
DLIB_TEST(img2[0][3] == 0);
DLIB_TEST(img2[1][0] == 0);
DLIB_TEST(std::abs(img2[1][1] - -4.5 - 8) < 1e-14);
DLIB_TEST(std::abs(img2[1][2] - -4.5 - 8) < 1e-14);
DLIB_TEST(img2[1][3] == 0);
DLIB_TEST(img2[2][0] == 0);
......
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