• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

extend.cc

00001 #include <mln/core/image/dmorph/extended.hh>
00002 #include <mln/core/image/dmorph/image_if.hh>
00003 #include <mln/core/routine/extend.hh>
00004 #include <mln/core/var.hh>
00005 
00006 #include <mln/data/transform.hh>
00007 #include <mln/data/paste.hh>
00008 
00009 #include <mln/fun/p2b/big_chess.hh>
00010 
00011 #include <mln/value/rgb8.hh>
00012 #include <mln/literal/colors.hh>
00013 
00014 #include <tests/data.hh>
00015 
00016 #include <doc/tools/sample_utils.hh>
00017 
00018 namespace mln
00019 {
00020 
00021   struct saturate_rgb8 : public Function_v2v<saturate_rgb8>
00022   {
00023 
00024     typedef value::rgb8 result;
00025 
00026     value::rgb8 operator()(const value::rgb8& v) const
00027     {
00028       value::rgb8 v2 = v;
00029       v2.red() > 50 ? v2.red() -= 50 : v2.red() = 0;
00030       v2.green() > 50 ? v2.green() -= 50 : v2.green() = 0;
00031       v2.blue() > 50 ? v2.blue() -= 50 : v2.blue() = 0;
00032       return v2;
00033     }
00034 
00035   };
00036 
00037 } // end of namespace mln
00038 
00039 // \{
00040 namespace mln
00041 {
00042 
00043   struct my_ext : public Function_v2v<my_ext>
00044   {
00045 
00046     typedef value::rgb8 result;
00047 
00048     value::rgb8 operator()(const point2d& p) const
00049     {
00050       if ((p.row() + p.col()) % 20)
00051         return literal::black;
00052       return literal::white;
00053     }
00054 
00055   };
00056 
00057 } // end of namespace mln
00058 // \}
00059 
00060 int main()
00061 {
00062   using namespace mln;
00063   using value::rgb8;
00064 
00065   border::thickness = 5;
00066 
00067   // \{
00068   image2d<rgb8> lena;
00069   io::ppm::load(lena, MLN_IMG_DIR "/small.ppm");
00070   box2d bbox_enlarged = lena.domain();
00071   bbox_enlarged.enlarge(border::thickness);
00072   mln_VAR(ima_roi, lena | fun::p2b::big_chess<box2d>(lena.domain(), 10));
00073   // \}
00074 
00075   image2d<rgb8> tmp;
00076   initialize(tmp, lena);
00077   data::fill(tmp, literal::black);
00078   data::paste(ima_roi, tmp);
00079   doc::ppmsave(tmp, "extend");
00080 
00081   // \{
00082   mln_VAR(ext_with_val, extended_to(extend(ima_roi, literal::blue), bbox_enlarged));
00083   // \}
00084   doc::ppmsave(ext_with_val, "extend");
00085 
00086   // \{
00087   mln_VAR(ext_with_fun, extended_to(extend(ima_roi, my_ext()), bbox_enlarged));
00088   // \}
00089   doc::ppmsave(ext_with_fun, "extend");
00090 
00091 
00092   // \{
00093   mln_VAR(ext_with_ima, extend(ima_roi, lena));
00094   // \}
00095   doc::ppmsave(ext_with_ima, "extend");
00096 
00097   image2d<bool> mask;
00098   initialize(mask, lena);
00099   data::fill(mask, true);
00100   data::fill((mask | ima_roi.domain()).rw(), false);
00101   mln_VAR(ima_ext, data::transform(lena | (pw::value(mask) != false), saturate_rgb8()));
00102   data::paste(ima_ext, lena);
00103   data::paste(ima_roi, lena);
00104   doc::ppmsave(lena, "extend");
00105 
00106 }

Generated on Tue Oct 4 2011 15:23:45 for Milena (Olena) by  doxygen 1.7.1