Commit ff77bcc1 authored by Davis King's avatar Davis King

I went through the image transforms and updated their specs and a few other

things so that they still make sense now that I'm letting pixels be signed
as well as unsigned.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403972
parent 7861ded2
...@@ -97,7 +97,7 @@ namespace dlib ...@@ -97,7 +97,7 @@ namespace dlib
out_image_type& vert out_image_type& vert
) )
{ {
COMPILE_TIME_ASSERT(is_signed_type<typename out_image_type::type>::value); COMPILE_TIME_ASSERT(pixel_traits<typename out_image_type::type>::is_unsigned == false);
DLIB_ASSERT( (((void*)&in_img != (void*)&horz) && ((void*)&in_img != (void*)&vert) && ((void*)&vert != (void*)&horz)), DLIB_ASSERT( (((void*)&in_img != (void*)&horz) && ((void*)&in_img != (void*)&vert) && ((void*)&vert != (void*)&horz)),
"\tvoid sobel_edge_detector(in_img, horz, vert)" "\tvoid sobel_edge_detector(in_img, horz, vert)"
<< "\n\tYou can't give the same image as more than one argument" << "\n\tYou can't give the same image as more than one argument"
...@@ -107,10 +107,10 @@ namespace dlib ...@@ -107,10 +107,10 @@ namespace dlib
); );
const long vert_filter[3][3] = {{-1,-2,-1}, const int vert_filter[3][3] = {{-1,-2,-1},
{0,0,0}, {0,0,0},
{1,2,1}}; {1,2,1}};
const long horz_filter[3][3] = { {-1,0,1}, const int horz_filter[3][3] = { {-1,0,1},
{-2,0,2}, {-2,0,2},
{-1,0,1}}; {-1,0,1}};
...@@ -135,9 +135,11 @@ namespace dlib ...@@ -135,9 +135,11 @@ namespace dlib
{ {
for (long c = first_col; c < last_col; ++c) for (long c = first_col; c < last_col; ++c)
{ {
unsigned long p; typedef typename pixel_traits<typename in_image_type::type>::basic_pixel_type bp_type;
long horz_temp = 0;
long vert_temp = 0; typename promote<bp_type>::type p, horz_temp, vert_temp;
horz_temp = 0;
vert_temp = 0;
for (long m = 0; m < M; ++m) for (long m = 0; m < M; ++m)
{ {
for (long n = 0; n < N; ++n) for (long n = 0; n < N; ++n)
...@@ -145,13 +147,13 @@ namespace dlib ...@@ -145,13 +147,13 @@ namespace dlib
// pull out the current pixel and put it into p // pull out the current pixel and put it into p
p = get_pixel_intensity(in_img[r-M/2+m][c-N/2+n]); p = get_pixel_intensity(in_img[r-M/2+m][c-N/2+n]);
horz_temp += static_cast<long>(p)*horz_filter[m][n]; horz_temp += p*horz_filter[m][n];
vert_temp += static_cast<long>(p)*vert_filter[m][n]; vert_temp += p*vert_filter[m][n];
} }
} }
horz[r][c] = horz_temp; assign_pixel(horz[r][c] , horz_temp);
vert[r][c] = vert_temp; assign_pixel(vert[r][c] , vert_temp);
} }
} }
......
...@@ -45,7 +45,7 @@ namespace dlib ...@@ -45,7 +45,7 @@ namespace dlib
- in_image_type == is an implementation of array2d/array2d_kernel_abstract.h - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- out_image_type == is an implementation of array2d/array2d_kernel_abstract.h - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename in_image_type::type> must be defined - pixel_traits<typename in_image_type::type> must be defined
out_image_type::type == a signed integral type - pixel_traits<typename out_image_type::type>::is_unsigned == false
- (&in_img != &horz) && (&in_img != &vert) && (&vert != &horz) - (&in_img != &horz) && (&in_img != &vert) && (&vert != &horz)
(i.e. all three images are different image objects) (i.e. all three images are different image objects)
ensures ensures
......
...@@ -25,6 +25,8 @@ namespace dlib ...@@ -25,6 +25,8 @@ namespace dlib
matrix<unsigned long,R,C,MM>& hist matrix<unsigned long,R,C,MM>& hist
) )
{ {
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::is_unsigned == true );
// make sure hist is the right size // make sure hist is the right size
if (R == 1) if (R == 1)
hist.set_size(1,pixel_traits<typename in_image_type::type>::max()+1); hist.set_size(1,pixel_traits<typename in_image_type::type>::max()+1);
...@@ -59,6 +61,9 @@ namespace dlib ...@@ -59,6 +61,9 @@ namespace dlib
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::is_unsigned == true );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::is_unsigned == true );
typedef typename in_image_type::type in_pixel_type; typedef typename in_image_type::type in_pixel_type;
typedef typename out_image_type::type out_pixel_type; typedef typename out_image_type::type out_pixel_type;
......
...@@ -25,6 +25,8 @@ namespace dlib ...@@ -25,6 +25,8 @@ namespace dlib
- out_image_type == is an implementation of array2d/array2d_kernel_abstract.h - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename in_image_type::type>::has_alpha == false - pixel_traits<typename in_image_type::type>::has_alpha == false
- pixel_traits<typename out_image_type::type>::has_alpha == false - pixel_traits<typename out_image_type::type>::has_alpha == false
- pixel_traits<typename in_image_type::type>::is_unsigned == true
- pixel_traits<typename out_image_type::type>::is_unsigned == true
ensures ensures
- #out_img == the histogram equalized version of in_img - #out_img == the histogram equalized version of in_img
- #out_img.nc() == in_img.nc() - #out_img.nc() == in_img.nc()
...@@ -46,6 +48,7 @@ namespace dlib ...@@ -46,6 +48,7 @@ namespace dlib
/*! /*!
requires requires
- in_image_type == is an implementation of array2d/array2d_kernel_abstract.h - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename in_image_type::type>::is_unsigned == true
- hist must be capable of representing a column vector of length - hist must be capable of representing a column vector of length
pixel_traits<typename in_image_type>::max(). I.e. if R and C are nonzero pixel_traits<typename in_image_type>::max(). I.e. if R and C are nonzero
then they must be values that don't conflict with the previous sentence. then they must be values that don't conflict with the previous sentence.
......
...@@ -24,16 +24,21 @@ namespace dlib ...@@ -24,16 +24,21 @@ namespace dlib
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(original.nr() > 10 && original.nc() > 10, DLIB_ASSERT(original.nr() > 10 && original.nc() > 10 &&
is_same_object(original, down) == false,
"\t void pyramid_down::operator()" "\t void pyramid_down::operator()"
<< "\n\t original.nr(): " << original.nr() << "\n\t original.nr(): " << original.nr()
<< "\n\t original.nc(): " << original.nc() << "\n\t original.nc(): " << original.nc()
<< "\n\t this: " << this << "\n\t is_same_object(original, down): " << is_same_object(original, down)
<< "\n\t this: " << this
); );
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false );
typedef typename pixel_traits<typename in_image_type::type>::basic_pixel_type bp_type;
typedef typename promote<bp_type>::type ptype;
typename array2d<ptype>::kernel_1a temp_img;
temp_img.set_size(original.nr(), (original.nc()-3)/2); temp_img.set_size(original.nr(), (original.nc()-3)/2);
down.set_size((original.nr()-3)/2, (original.nc()-3)/2); down.set_size((original.nr()-3)/2, (original.nc()-3)/2);
...@@ -50,11 +55,11 @@ namespace dlib ...@@ -50,11 +55,11 @@ namespace dlib
long oc = 0; long oc = 0;
for (long c = 0; c < temp_img.nc(); ++c) for (long c = 0; c < temp_img.nc(); ++c)
{ {
unsigned long pix1; ptype pix1;
unsigned long pix2; ptype pix2;
unsigned long pix3; ptype pix3;
unsigned long pix4; ptype pix4;
unsigned long pix5; ptype pix5;
assign_pixel(pix1, original[r][oc]); assign_pixel(pix1, original[r][oc]);
assign_pixel(pix2, original[r][oc+1]); assign_pixel(pix2, original[r][oc+1]);
...@@ -78,11 +83,11 @@ namespace dlib ...@@ -78,11 +83,11 @@ namespace dlib
{ {
for (long c = 0; c < temp_img.nc(); ++c) for (long c = 0; c < temp_img.nc(); ++c)
{ {
unsigned long temp = temp_img[r-2][c] + ptype temp = temp_img[r-2][c] +
temp_img[r-1][c]*4 + temp_img[r-1][c]*4 +
temp_img[r ][c]*6 + temp_img[r ][c]*6 +
temp_img[r-1][c]*4 + temp_img[r-1][c]*4 +
temp_img[r-2][c]; temp_img[r-2][c];
assign_pixel(down[dr][c],temp/256); assign_pixel(down[dr][c],temp/256);
} }
...@@ -93,7 +98,6 @@ namespace dlib ...@@ -93,7 +98,6 @@ namespace dlib
private: private:
array2d<unsigned long>::kernel_1a temp_img;
}; };
......
...@@ -29,6 +29,7 @@ namespace dlib ...@@ -29,6 +29,7 @@ namespace dlib
requires requires
- original.nr() > 10 - original.nr() > 10
- original.nc() > 10 - original.nc() > 10
- is_same_object(original, down) == false
- in_image_type == is an implementation of array2d/array2d_kernel_abstract.h - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- out_image_type == is an implementation of array2d/array2d_kernel_abstract.h - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename in_image_type::type>::has_alpha == false - pixel_traits<typename in_image_type::type>::has_alpha == false
......
...@@ -35,6 +35,8 @@ namespace dlib ...@@ -35,6 +35,8 @@ namespace dlib
const image_type& img const image_type& img
) )
{ {
COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::is_unsigned == true );
unsigned long pixel; unsigned long pixel;
int_img.set_size(img.nr(), img.nc()); int_img.set_size(img.nr(), img.nc());
......
...@@ -52,7 +52,7 @@ namespace dlib ...@@ -52,7 +52,7 @@ namespace dlib
/*! /*!
requires requires
- image_type == a type that implements the array2d/array2d_kernel_abstract.h interface - image_type == a type that implements the array2d/array2d_kernel_abstract.h interface
- pixel_traits<image_type::type> must be defined - pixel_traits<typename image_type::type>::is_unsigned == true
ensures ensures
- #nr() == img.nr() - #nr() == img.nr()
- #nc() == img.nc() - #nc() == img.nc()
......
...@@ -67,15 +67,16 @@ namespace dlib ...@@ -67,15 +67,16 @@ namespace dlib
{ {
for (long c = first_col; c < last_col; ++c) for (long c = first_col; c < last_col; ++c)
{ {
unsigned long p; typedef typename pixel_traits<typename in_image_type::type>::basic_pixel_type bp_type;
long temp = 0; typename promote<bp_type>::type p;
typename promote<bp_type>::type temp = 0;
for (long m = 0; m < M; ++m) for (long m = 0; m < M; ++m)
{ {
for (long n = 0; n < N; ++n) for (long n = 0; n < N; ++n)
{ {
// pull out the current pixel and put it into p // pull out the current pixel and put it into p
p = get_pixel_intensity(in_img[r-M/2+m][c-N/2+n]); p = get_pixel_intensity(in_img[r-M/2+m][c-N/2+n]);
temp += static_cast<long>(p)*filter[m][n]; temp += p*filter[m][n];
} }
} }
...@@ -94,12 +95,9 @@ namespace dlib ...@@ -94,12 +95,9 @@ namespace dlib
} }
} }
// apply our new value for the intensity
p = static_cast<unsigned long>(temp);
// save this pixel to the output image // save this pixel to the output image
assign_pixel(out_img[r][c], in_img[r][c]); assign_pixel(out_img[r][c], in_img[r][c]);
assign_pixel_intensity(out_img[r][c],p); assign_pixel_intensity(out_img[r][c], temp);
} }
} }
} }
......
...@@ -69,6 +69,8 @@ namespace dlib ...@@ -69,6 +69,8 @@ namespace dlib
{ {
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::is_unsigned == true );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::is_unsigned == true );
COMPILE_TIME_ASSERT(pixel_traits<typename out_image_type::type>::grayscale); COMPILE_TIME_ASSERT(pixel_traits<typename out_image_type::type>::grayscale);
...@@ -206,7 +208,7 @@ namespace dlib ...@@ -206,7 +208,7 @@ namespace dlib
{ {
for (long c = 0; c < in_img.nc(); ++c) for (long c = 0; c < in_img.nc(); ++c)
{ {
unsigned long p; typename pixel_traits<typename in_image_type::type>::basic_pixel_type p;
assign_pixel(p,in_img[r][c]); assign_pixel(p,in_img[r][c]);
if (p >= upper_thresh) if (p >= upper_thresh)
{ {
......
...@@ -56,6 +56,8 @@ namespace dlib ...@@ -56,6 +56,8 @@ namespace dlib
- pixel_traits<typename out_image_type::type>::grayscale == true - pixel_traits<typename out_image_type::type>::grayscale == true
- pixel_traits<typename in_image_type::type>::has_alpha == false - pixel_traits<typename in_image_type::type>::has_alpha == false
- pixel_traits<typename out_image_type::type>::has_alpha == false - pixel_traits<typename out_image_type::type>::has_alpha == false
- pixel_traits<typename in_image_type::type>::is_unsigned == true
- pixel_traits<typename out_image_type::type>::is_unsigned == true
ensures ensures
- #out_img == the thresholded version of in_img (in_img is converted to a grayscale - #out_img == the thresholded version of in_img (in_img is converted to a grayscale
intensity image if it is color). Pixels in in_img with grayscale values >= thresh intensity image if it is color). Pixels in in_img with grayscale values >= thresh
......
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