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

fill_with_image.cc

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 #include <mln/data/fill_with_value.hh>
00027 #include <mln/data/fill_with_image.hh>
00028 #include <mln/data/compare.hh>
00029 
00030 #include <mln/core/image/image1d.hh>
00031 #include <mln/core/image/image2d.hh>
00032 #include <mln/core/image/image3d.hh>
00033 #include <mln/pw/image.hh>
00034 #include <mln/core/image/flat_image.hh>
00035 #include <mln/core/image/vmorph/cast_image.hh>
00036 #include <mln/core/image/dmorph/image_if.hh>
00037 #include <mln/core/image/dmorph/sub_image.hh>
00038 #include <mln/core/image/dmorph/extension_val.hh>
00039 
00040 #include <mln/fun/p2b/chess.hh>
00041 #include <mln/fun/p2v/iota.hh>
00042 
00043 #include <mln/debug/iota.hh>
00044 #include <mln/debug/println.hh>
00045 #include <mln/trace/all.hh>
00046 
00047 
00048 int main()
00049 {
00050   using namespace mln;
00051   const unsigned size = 100;
00052 
00053   // tests in two dimension
00054   {
00055     box2d b(point2d(1,2), point2d(2,4));
00056     image2d<int> ima(b, 2);
00057     debug::iota(ima);
00058 
00059     box2d b2(point2d(-1,-2), point2d(3,6));
00060     image2d<int> ima2(b2, 0);
00061     debug::iota(ima2);
00062 
00063     data::fill_with_image(ima, ima2); // Not so fast version...
00064     mln_assertion(ima == (ima2 | b));
00065   }
00066 
00067 
00068   // 2d tests
00069   {
00070     image2d<unsigned int> ima(size, size);
00071     image2d<unsigned int> ima2(size, size);
00072     debug::iota(ima2);
00073 
00074     data::fill_with_image(ima, ima2);
00075     mln_assertion(ima == ima2);
00076   }
00077 
00078   {
00079     box2d b(point2d(1,2), point2d(2,4));
00080     image2d<int> ima(b, 2);
00081 
00082     box2d b2(point2d(-1,-2), point2d(3,6));
00083     image2d<int> ima2(b2, 0);
00084     debug::iota(ima2);
00085 
00086     data::fill_with_image(ima, ima2);
00087     mln_assertion(ima == (ima2 | b));
00088   }
00089 
00090   {
00091     typedef image2d<unsigned char> I;
00092     typedef image_if<I, fun::p2b::chess> II;
00093 
00094     I ima(size, size);
00095     I ima2(size, size);
00096     data::fill_with_value(ima, 51);
00097     data::fill_with_value(ima2, 42);
00098 
00099     II ima_if = ima | fun::p2b::chess();
00100     data::fill_with_image(ima_if, ima2);
00101 
00102     II::piter p(ima_if.domain());
00103     for_all(p)
00104       mln_assertion(ima_if(p) == 42);
00105 
00106   }
00107 
00108   // tests in three dimension
00109   {
00110     box3d b(point3d(1,2,1), point3d(2,4,3));
00111     image3d<int> ima(b, 2);
00112     debug::iota(ima);
00113 
00114     box3d b2(point3d(-1,-2,-1), point3d(3,6,3));
00115     image3d<int> ima2(b2, 2);
00116     debug::iota(ima2);
00117 
00118     image3d<int> ima3(b, 2);
00119 
00120     data::fill_with_image(ima, ima2); // Not so fast version...
00121     mln_assertion(ima == (ima2 | b));
00122 
00123     data::fill_with_image(ima3, ima); // Fast version...
00124     mln_assertion(ima == ima3);
00125   }
00126 
00127   // image 1d test
00128   {
00129     image1d<unsigned short> ima(size);
00130     image1d<unsigned short> out(size);
00131 
00132     debug::iota(ima);
00133     data::fill_with_image(out, ima);
00134 
00135     mln_assertion(ima == out);
00136   }
00137 
00138 
00139   // pw image test
00140   {
00141     fun::p2v::iota f;
00142     const pw::image<fun::p2v::iota, mln::box2d> ima(f, make::box2d(-2,-2, 15,15));
00143     image2d<short unsigned int> out(8, 8);
00144 
00145     data::fill(out, (short unsigned int)0);
00146     data::fill_with_image(out, ima);
00147   }
00148 
00149   // flat image test
00150   {
00151     flat_image<short, box2d> ima(5, mln::make::box2d(size, size));
00152     image2d<unsigned short> out(size, size);
00153 
00154     data::fill_with_value(ima, 51);
00155     data::fill_with_image(out, ima);
00156 
00157     mln_assertion(ima == out);
00158   }
00159 
00160   // image if test
00161   {
00162     typedef image2d<unsigned short> I;
00163     typedef image_if<I, fun::p2b::chess> II;
00164 
00165     I ima(size, size);
00166     I out(size, size);
00167     II ima_if = ima | fun::p2b::chess();
00168 
00169     data::fill_with_value(ima, 42);
00170     data::fill_with_value(out, 0);
00171     data::fill_with_image(ima_if, ima);
00172 
00173     mln_piter_(II) p(ima_if.domain());
00174     for_all(p)
00175       mln_assertion(ima_if(p) == ima(p));
00176   }
00177 
00178   // cast image test
00179   {
00180     typedef image2d<unsigned short> I;
00181     typedef cast_image_<int, I> II;
00182 
00183     I in(size, size);
00184     II cast(in);
00185     I out(size, size);
00186 
00187     data::fill(in, (unsigned short)51);
00188     data::fill(out, (unsigned short)42);
00189 
00190     data::fill_with_image(out, cast);
00191 
00192     mln_assertion(cast == out);
00193   }
00194 
00195   // sub_image test
00196    {
00197      typedef image2d<int> I;
00198      typedef sub_image< image2d<int>, box2d > II;
00199 
00200      I ima(size, size);
00201      I out(size, size);
00202      II sub_ima(ima, make::box2d(4,4, 10,10));
00203 
00204 
00205      data::fill(ima, 51);
00206      data::fill(out, 0);
00207      data::fill_with_image(sub_ima, ima);
00208 
00209      II::piter p(sub_ima.domain());
00210      for_all(p)
00211        mln_assertion(sub_ima(p) == ima(p));
00212    }
00213 
00214    // extended image test
00215   {
00216     typedef image2d<int> I;
00217     typedef extension_val< image2d<int> > II;
00218     typedef image2d<unsigned short> III;
00219 
00220     I ima(size, size);
00221     II extend_ima(ima, 5);
00222     III out(size, size);
00223 
00224     data::fill(ima, 51);
00225     data::fill_with_image(out, extend_ima);
00226 
00227     mln_assertion(out == extend_ima);
00228   }
00229 
00230 }

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