00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_LINEAR_SOBEL_2D_HH
00027 # define MLN_LINEAR_SOBEL_2D_HH
00028
00034
00035 # include <mln/trait/ch_value.hh>
00036 # include <mln/trait/value/nature.hh>
00037
00038 # include <mln/metal/int.hh>
00039
00040 # include <mln/arith/plus.hh>
00041 # include <mln/data/abs.hh>
00042 # include <mln/fun/x2v/l1_norm.hh>
00043 # include <mln/fun/vv2v/vec.hh>
00044 # include <mln/linear/convolve_2x1d.hh>
00045
00046
00047
00048 namespace mln
00049 {
00050
00051 namespace linear
00052 {
00053
00057 template <typename I>
00058 mln_ch_convolve(I, int)
00059 sobel_2d_h(const Image<I>& input);
00060
00062 template <typename I>
00063 mln_ch_convolve(I, int)
00064 sobel_2d_v(const Image<I>& input);
00066
00068 template <typename I>
00069 mln_ch_convolve_grad(I, int)
00070 sobel_2d(const Image<I>& input);
00072
00074 template <typename I>
00075 mln_ch_convolve(I, int)
00076 sobel_2d_l1_norm(const Image<I>& input);
00078
00079
00080 # ifndef MLN_INCLUDE_ONLY
00081
00082
00083
00084
00085 template <typename I>
00086 inline
00087 mln_ch_convolve(I, int)
00088 sobel_2d_h(const Image<I>& input)
00089 {
00090 trace::entering("linear::sobel_2d_h");
00091 mln_precondition(exact(input).is_valid());
00092
00093 int wh[] = { -1, 0, 1 };
00094 int wv[] = { 1,
00095 2,
00096 1 };
00097 mln_ch_convolve(I, int) output = convolve_2x1d(input, wh, wv);
00098
00099 trace::exiting("linear::sobel_2d_h");
00100 return output;
00101 }
00102
00103
00104 template <typename I>
00105 inline
00106 mln_ch_convolve(I, int)
00107 sobel_2d_v(const Image<I>& input)
00108 {
00109 trace::entering("linear::sobel_2d_v");
00110 mln_precondition(exact(input).is_valid());
00111
00112 int wh[] = { 1, 2, 1 };
00113 int wv[] = { -1,
00114 0,
00115 +1 };
00116 mln_ch_convolve(I, int) output = convolve_2x1d(input, wh, wv);
00117
00118 trace::exiting("linear::sobel_2d_v");
00119 return output;
00120 }
00121
00122
00123 template <typename I>
00124 mln_ch_convolve_grad(I, int)
00125 sobel_2d(const Image<I>& input)
00126 {
00127 trace::entering("linear::sobel_2d");
00128 mln_precondition(exact(input).is_valid());
00129
00130 typedef mln_ch_convolve(I, int) J;
00131 J h = sobel_2d_h(input),
00132 v = sobel_2d_v(input);
00133 fun::vv2v::vec<mln_value(J)> f;
00134 mln_ch_convolve_grad(I, int) output = data::transform(h, v, f);
00135
00136 trace::exiting("linear::sobel_2d");
00137 return output;
00138 }
00139
00140
00141 template <typename I>
00142 mln_ch_convolve(I, int)
00143 sobel_2d_l1_norm(const Image<I>& input)
00144 {
00145 trace::entering("linear::sobel_2d_norm_l1");
00146 mln_precondition(exact(input).is_valid());
00147
00148 typedef mln_ch_convolve_grad(I, int) G;
00149 G grad = sobel_2d(input);
00150 fun::x2v::l1_norm<mln_value(G)> f;
00151 mln_ch_convolve(I, int) output = data::transform(grad, f);
00152
00153 trace::exiting("linear::sobel_2d");
00154 return output;
00155 }
00156
00157 # endif // ! MLN_INCLUDE_ONLY
00158
00159 }
00160
00161 }
00162
00163
00164 #endif // ! MLN_LINEAR_SOBEL_2D_HH