1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_THRESHOLDINg_ABSTRACT_
#ifdef DLIB_THRESHOLDINg_ABSTRACT_
#include "../pixel.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
const unsigned char on_pixel = 255;
const unsigned char off_pixel = 0;
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void threshold_image (
const in_image_type& in_img,
out_image_type& out_img,
typename pixel_traits<typename in_image_type::type>::basic_pixel_type thresh
);
/*!
requires
- in_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 out_image_type::type>::grayscale == true
- pixel_traits<typename in_image_type::type>::has_alpha == false
- pixel_traits<typename out_image_type::type>::has_alpha == false
ensures
- #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
have an output value of on_pixel and all others have a value of off_pixel.
- #out_img.nc() == in_img.nc()
- #out_img.nr() == in_img.nr()
!*/
template <
typename image_type
>
void threshold_image (
image_type& img,
typename pixel_traits<typename image_type::type>::basic_pixel_type thresh
);
/*!
requires
- it is valid to call threshold_image(img,img,thresh);
ensures
- calls threshold_image(img,img,thresh);
!*/
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void auto_threshold_image (
const in_image_type& in_img,
out_image_type& out_img
);
/*!
requires
- in_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 out_image_type::type>::grayscale == true
- pixel_traits<typename in_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
- #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
have an output value of on_pixel and all others have a value of off_pixel.
- The thresh value used is determined by performing a k-means clustering
on the input image histogram with a k of 2. The point between the two
means found is used as the thresh value.
- #out_img.nc() == in_img.nc()
- #out_img.nr() == in_img.nr()
!*/
template <
typename image_type
>
void auto_threshold_image (
image_type& img
);
/*!
requires
- it is valid to call auto_threshold_image(img,img);
ensures
- calls auto_threshold_image(img,img);
!*/
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void hysteresis_threshold (
const in_image_type& in_img,
out_image_type& out_img,
typename pixel_traits<typename in_image_type::type>::basic_pixel_type lower_thresh,
typename pixel_traits<typename in_image_type::type>::basic_pixel_type upper_thresh
);
/*!
requires
- in_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 out_image_type::type>::grayscale == true
- pixel_traits<typename in_image_type::type>::has_alpha == false
- pixel_traits<typename out_image_type::type>::has_alpha == false
- lower_thresh <= upper_thresh
- is_same_object(in_img, out_img) == false
ensures
- #out_img == the hysteresis 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 >= upper_thresh have an output value of on_pixel and all others have a
value of off_pixel unless they are >= lower_thresh and are adjacent to a pixel
with a value >= upper_thresh in which case they have a value of on_pixel.
- #out_img.nc() == in_img.nc()
- #out_img.nr() == in_img.nr()
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_THRESHOLDINg_ABSTRACT_
|