Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 // Facades. 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 } // end of namespace mln::linear 00160 00161 } // end of namespace mln 00162 00163 00164 #endif // ! MLN_LINEAR_SOBEL_2D_HH