Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_LABELING_MEAN_VALUES_HH 00027 # define MLN_LABELING_MEAN_VALUES_HH 00028 00036 00037 00038 # include <mln/core/concept/image.hh> 00039 # include <mln/core/alias/vec3d.hh> 00040 00041 # include <mln/accu/stat/mean.hh> 00042 00043 # include <mln/data/transform.hh> 00044 00045 # include <mln/labeling/compute.hh> 00046 00047 # include <mln/literal/colors.hh> 00048 00049 00050 namespace mln 00051 { 00052 00053 // Forward declaration 00054 namespace value 00055 { 00056 template <unsigned n> struct rgb; 00057 } 00058 00059 00060 namespace labeling 00061 { 00062 00063 template <typename I, typename L> 00064 mln_concrete(I) 00065 mean_colors(const Image<I>& input, 00066 const Image<L>& lbl, mln_value(L) nlabels); 00067 00068 00069 # ifndef MLN_INCLUDE_ONLY 00070 00071 namespace internal 00072 { 00073 00074 template <typename I, typename L> 00075 void 00076 mean_values_tests(const Image<I>& input, 00077 const Image<L>& lbl, mln_value(L) nlabels) 00078 { 00079 mln_precondition(exact(input).is_valid()); 00080 mln_precondition(exact(lbl).is_valid()); 00081 (void) input; 00082 (void) lbl; 00083 (void) nlabels; 00084 } 00085 00086 } // end of namespace mln::labeling::internal 00087 00088 00089 namespace impl 00090 { 00091 00092 namespace generic 00093 { 00094 00095 template <typename I, typename L> 00096 mln_concrete(I) 00097 mean_values(const Image<I>& input_, 00098 const Image<L>& lbl_, mln_value(L) nlabels) 00099 { 00100 trace::entering("mln::labeling::impl::generic::mean_values"); 00101 00102 internal::mean_values_tests(input_, lbl_, nlabels); 00103 00104 const I& input = exact(input_); 00105 const L& lbl = exact(lbl_); 00106 typedef mln_value(L) LV; 00107 typedef mln_value(I) IV; 00108 00109 util::array<float> m_3f 00110 = labeling::compute(accu::stat::mean<IV>(), 00111 input, // input color image 00112 lbl, // watershed labeling 00113 nlabels); 00114 m_3f[0] = 0.f; 00115 00116 util::array<IV> m; 00117 convert::from_to(m_3f, m); 00118 m[0] = 150u; //FIXME: handle label 0 correctly. 00119 00120 mln_concrete(I) output = data::transform(lbl, m); 00121 00122 trace::exiting("mln::labeling::impl::generic::mean_values"); 00123 return output; 00124 } 00125 00126 } 00127 00128 template <typename I, typename L> 00129 mln_concrete(I) 00130 mean_values_rgb(const Image<I>& input_, 00131 const Image<L>& lbl_, mln_value(L) nlabels) 00132 { 00133 trace::entering("mln::labeling::impl::mean_values_rgb"); 00134 00135 internal::mean_values_tests(input_, lbl_, nlabels); 00136 00137 const I& input = exact(input_); 00138 const L& lbl = exact(lbl_); 00139 00140 util::array<vec3d_f> m_3f = labeling::compute(accu::stat::mean<mln_value(I)>(), 00141 input, // input color image 00142 lbl, // watershed labeling 00143 nlabels); 00144 m_3f[0] = literal::zero; 00145 00146 util::array<mln_value(I)> m; 00147 convert::from_to(m_3f, m); 00148 m[0] = literal::yellow; //FIXME: handle label 0 correctly. 00149 00150 mln_concrete(I) output = data::transform(lbl, 00151 convert::to< fun::i2v::array<mln_value(I)> >(m)); 00152 00153 00154 trace::exiting("mln::labeling::impl::mean_values_rgb"); 00155 return output; 00156 } 00157 00158 } // end of namespace mln::morpho::impl 00159 00160 00161 namespace internal 00162 { 00163 00164 template <unsigned n, typename I, typename L> 00165 mln_concrete(I) 00166 mean_values_dispatch(const value::rgb<n>&, 00167 const Image<I>& input, 00168 const Image<L>& lbl, mln_value(L) nlabels) 00169 { 00170 return impl::mean_values_rgb(input, lbl, nlabels); 00171 } 00172 00173 template <typename I, typename L> 00174 mln_concrete(I) 00175 mean_values_dispatch(const mln_value(I)&, 00176 const Image<I>& input, 00177 const Image<L>& lbl, mln_value(L) nlabels) 00178 { 00179 return impl::generic::mean_values(input, lbl, nlabels); 00180 } 00181 00182 template <typename I, typename L> 00183 mln_concrete(I) 00184 mean_values_dispatch(const Image<I>& input, 00185 const Image<L>& lbl, mln_value(L) nlabels) 00186 { 00187 return mean_values_dispatch(mln_value(I)(), input, lbl, nlabels); 00188 } 00189 00190 } // end of namespace mln::morpho::internal 00191 00192 00193 00194 // Facade 00195 00196 template <typename I, typename L> 00197 mln_concrete(I) 00198 mean_values(const Image<I>& input, 00199 const Image<L>& lbl, mln_value(L) nlabels) 00200 00201 { 00202 trace::entering("mln::labeling::mean_values"); 00203 00204 internal::mean_values_tests(input, lbl, nlabels); 00205 00206 mln_concrete(I) output = internal::mean_values_dispatch(input, lbl, nlabels); 00207 00208 trace::exiting("mln::labeling::mean_values"); 00209 return output; 00210 } 00211 00212 00213 # endif // !MLN_INCLUDE_ONLY 00214 00215 } // end of namespace mln::labeling 00216 00217 } // end of namespace mln 00218 00219 #endif // ! MLN_LABELING_MEAN_VALUES_HH