2005-03-31 Thierry GERAUD theo@tegucigalpa.lrde.epita.fr
* oln/core/abstract/image_like_.hh: Set concrete_type property. * oln/core/abstract/image_operator.hh: Add typedefs. * oln/morpho/dilation.hh (proc::dilation): New. (impl::dilation_type): Rename as... (dilation_ret): ...this. (dilation_type_classic): Rename as... (generic_dilation): ...this. * oln/morpho/erosion.hh: Likewise.
Index: oln/core/abstract/image_like_.hh =================================================================== --- oln/core/abstract/image_like_.hh (revision 99) +++ oln/core/abstract/image_like_.hh (working copy) @@ -54,9 +54,16 @@ typedef abstract::image_by_delegation<I, E> ret; };
+ // props
+ template <typename I, typename E> + struct set_props < category::image, abstract::image_like_<I, E> > : public props_ofcategory::image + { + typedef oln_type_of(I, concrete) concrete_type; + };
+ namespace abstract {
/// Mutable version of image_like_. Index: oln/core/abstract/image_operator.hh =================================================================== --- oln/core/abstract/image_operator.hh (revision 99) +++ oln/core/abstract/image_operator.hh (working copy) @@ -107,6 +107,7 @@ }
box<O> output; + typedef O output_type;
protected: image_operator() {} @@ -120,6 +121,7 @@ struct image_unary_operator : public image_operator<O, E> { box<const I> input; + typedef I input_type;
protected:
@@ -140,7 +142,10 @@ {
box<const I1> input1; + typedef I1 input1_type; + box<const I2> input2; + typedef I2 input2_type;
protected:
Index: oln/morpho/dilation.hh =================================================================== --- oln/morpho/dilation.hh (revision 99) +++ oln/morpho/dilation.hh (working copy) @@ -31,13 +31,33 @@ # include <oln/basics.hh> # include <oln/morpho/stat.hh> # include <oln/core/abstract/image_operator.hh> -// # include <oln/morpho/fast_morpho.hh> # include <mlc/cmp.hh>
namespace oln {
namespace morpho {
+ + + namespace proc { + + /// Dilation as a procedure (do not use it; prefer morpho::dilation). + + template<typename I, typename S> + oln_type_of(I, concrete) dilation(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) + { + oln_type_of(I, concrete) output(input.size()); + oln_type_of(I, fwd_piter) p(input.size()); + for_all (p) + output[p] = morpho::max(input, p, se); + return output; + } + + } // end of namespace oln::morpho::proc + + + /*! ** \brief Processing dilation. ** @@ -89,60 +109,70 @@ ** \image latex oln_morpho_dilation.png */
- // fwd decl - namespace impl { - template <typename I, typename E> struct dilation_type; - } + // fwd decl + template <typename I, typename E> struct dilation_ret;
}
// category template <typename I, typename E> - struct set_category< morpho::impl::dilation_type<I,E> > { typedef category::image ret; }; + struct set_category< morpho::dilation_ret<I,E> > { typedef category::image ret; };
// super_type template <typename I, typename E> - struct set_super_type< morpho::impl::dilation_type<I,E> > + struct set_super_type< morpho::dilation_ret<I,E> > { - typedef abstract::image_unary_operator<I, I, morpho::impl::dilation_type<I, E> > ret; // FIXME: see below + typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::dilation_ret<I, E> > ret; };
+ + namespace morpho {
- namespace impl { + /// Dilatation return.
- template <typename I, typename E> - struct dilation_type : public abstract::image_unary_operator<I, I, dilation_type<I, E> > - // FIXME: abstract::image_unary_operator<oln_type_of(I, concrete), ... - { - typedef abstract::image_unary_operator<I, I, dilation_type<I, E> > super_type; + template <typename I, typename S> + struct dilation_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I, S> > + { + typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I, S> > super_type; + typedef typename super_type::output_type output_type;
- const E se; + const S se;
- dilation_type(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) : - super_type(input.exact()), - se(se.exact()) - {} + dilation_ret(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) : + super_type(input.exact()), + se(se.exact()) + { + }
- }; + };
- template <typename I, typename E> - struct dilation_type_classic : public dilation_type<I, E> + + // Implementation: + + namespace impl { + + /// Dilation generic implementation. + + template <typename I, typename S> + struct generic_dilation : public dilation_ret<I, S> { - typedef dilation_type<I, E> super_type; + typedef dilation_ret<I, S> super_type; + typedef typename super_type::output_type output_type;
- dilation_type_classic(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) : + generic_dilation(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) : super_type(input, se) - {} + { + }
void impl_run() { mlc::is_true<mlc::type::eq<oln_type_of(I, size), - oln_type_of(E, size)>::ret>::ensure(); + oln_type_of(S, size)>::ret>::ensure();
- I tmp(input.size()); // FIXME: trick + output_type tmp(input.size()); // FIXME: trick output = tmp;
oln_type_of(I, fwd_piter) p(input.size()); @@ -151,29 +181,20 @@ } };
- } + } // end of namespace oln::morpho::impl
- template<typename I, typename E> - impl::dilation_type<I, E> - dilation(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) + + /// Dilation generic routine. + + template<typename I, typename S> + dilation_ret<I, S> dilation(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) { - impl::dilation_type_classic<I, E> tmp(input, se); + impl::generic_dilation<I, S> tmp(input, se); tmp.run(); return tmp; }
- -// namespace fast { -// template<class I, class E> -// oln_concrete_type(I) -// dilation(const abstract::non_vectorial_image<I>& input, -// const abstract::struct_elt<E>& se) -// { -// return fast_morpho<I, E, utils::histogram_max<oln_value_type(I)> > -// (input, se); -// } -// } } // end of morpho
} // end of oln Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 99) +++ oln/morpho/erosion.hh (working copy) @@ -30,13 +30,33 @@
# include <oln/basics.hh> # include <oln/morpho/stat.hh> -// # include <oln/morpho/fast_morpho.hh> # include <oln/core/abstract/image_operator.hh> # include <mlc/cmp.hh>
namespace oln {
namespace morpho { + + + namespace proc { + + /// Erosion as a procedure (do not use it; prefer morpho::erosion). + + template<typename I, typename S> + oln_type_of(I, concrete) dilation(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) + { + oln_type_of(I, concrete) output(input.size()); + oln_type_of(I, fwd_piter) p(input.size()); + for_all (p) + output[p] = morpho::min(input, p, se); + return output; + } + + } // end of namespace oln::morpho::proc + + + /*! ** \brief Perform a morphological erosion. ** @@ -84,58 +104,66 @@ */
// fwd decl - namespace impl { - template <typename I, typename E> struct erosion_type; - } + template <typename I, typename E> struct erosion_ret;
}
// category template <typename I, typename E> - struct set_category< morpho::impl::erosion_type<I,E> > { typedef category::image ret; }; + struct set_category< morpho::erosion_ret<I,E> > { typedef category::image ret; };
// super_type template <typename I, typename E> - struct set_super_type< morpho::impl::erosion_type<I,E> > + struct set_super_type< morpho::erosion_ret<I,E> > { - typedef abstract::image_unary_operator<I, I, morpho::impl::erosion_type<I, E> > ret; // FIXME: see below + typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::erosion_ret<I, E> > ret; };
+ namespace morpho {
- namespace impl { + /// Erosion return.
- template <typename I, typename E> - struct erosion_type : abstract::image_unary_operator<I, I, erosion_type<I, E> > - // FIXME: abstract::image_unary_operator<oln_type_of(I, concrete), ... - { - typedef abstract::image_unary_operator<I, I, erosion_type<I, E> > super_type; - const E se; + template <typename I, typename E> + struct erosion_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I, E> > + { + typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I, E> > super_type; + typedef typename super_type::output_type output_type;
- erosion_type(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) : - super_type(input), - se(se.exact()) - {} + const E se; + + erosion_ret(const abstract::image<I>& input, + const abstract::struct_elt<E>& se) : + super_type(input), + se(se.exact()) + { + } + + };
- };
- template <typename I, typename E> - struct erosion_type_classic : public erosion_type<I, E> + namespace impl { + + /// Erosion generic implementation. + + template <typename I, typename S> + struct generic_erosion : public erosion_ret<I, S> { - typedef erosion_type<I, E> super_type; + typedef erosion_ret<I, S> super_type; + typedef typename super_type::output_type output_type;
- erosion_type_classic(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) : + generic_erosion(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) : super_type(input, se) - {} + { + }
void impl_run() { mlc::is_true<mlc::type::eq<oln_type_of(I, size), - oln_type_of(E, size)>::ret>::ensure(); + oln_type_of(S, size)>::ret>::ensure();
- I tmp(input.size()); // FIXME: trick + output_type tmp(input.size()); // FIXME: trick output = tmp;
oln_type_of(I, fwd_piter) p(input.size()); @@ -144,67 +172,24 @@ } };
- } + } // end of namespace oln::morpho::impl
- template<typename I, typename E> - impl::erosion_type<I, E> - erosion(const abstract::non_vectorial_image<I>& input, - const abstract::struct_elt<E>& se) + /// Erosion generic routine. + + template<typename I, typename S> + erosion_ret<I, S> erosion(const abstract::image<I>& input, + const abstract::struct_elt<S>& se) { - impl::erosion_type_classic<I, E> tmp(input, se); + impl::generic_erosion<I, S> tmp(input, se); tmp.run(); return tmp; }
- namespace fast { - /*! - ** \brief Perform a morphological erosion. - ** - ** Compute the morphological erosion of input using se - ** as structuring element. - ** - ** \param I Exact type of the input image. - ** \param E Exact type of the structuring element. - ** - ** - ** \arg input Input image. - ** \arg se Structuring element to use. - ** - ** \code - ** #include <oln/basics2d.hh> - ** #include <oln/morpho/erosion.hh> - ** #include <oln/level/compare.hh> - ** #include <ntg/all.hh> - ** int main() - ** { - ** typedef oln::image2dntg::bin im_type; - ** - ** im_type im1(oln::load(IMG_IN "object.pbm")); - ** save(oln::morpho::fast::erosion(im1, oln::win_c8p()), - ** IMG_OUT "oln_morpho_fast_erosion.pbm"); - ** } - ** \endcode - ** - ** \image html object_pbm.png - ** \image latex object_pbm.png - ** => - ** \image html oln_morpho_fast_erosion.png - ** \image latex oln_morpho_fast_erosion.png - */ -// template<typename I, typename E> -// oln_concrete_type(I) -// erosion(const abstract::non_vectorial_image<I>& input, -// const abstract::struct_elt<E>& se) -// { -// return fast_morpho<I, E, utils::histogram_min<oln_value_type(I)> > -// (input, se); -// } - } // end of fast
- } // end of morpho + } // end of namespace oln::morpho
-} // end of oln +} // end of namespace oln
#endif // ! OLENA_MORPHO_EROSION_HH