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

equalize.hh

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_BORDER_EQUALIZE_HH
00027 # define MLN_BORDER_EQUALIZE_HH
00028 
00035 # include <mln/border/resize.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace border
00042   {
00043 
00058     template <typename I, typename J>
00059     void equalize(const Image<I>& ima1, const Image<J>& ima2,
00060                   unsigned min_thickness);
00061 
00062 
00063 
00064 # ifndef MLN_INCLUDE_ONLY
00065 
00066     namespace impl
00067     {
00068 
00069       template <typename I, typename J>
00070       inline
00071       void equalize_(const I& ima1, const J& ima2, unsigned min_thickness)
00072       {
00073         trace::entering("border::impl::equalize_");
00074 
00075         unsigned b1 = border::get(ima1), b2 = border::get(ima2);
00076 
00077         if (! (b1 == b2 && b2 >= min_thickness))
00078           // Something has to be done.
00079           {
00080             if (b1 < min_thickness && b2 < min_thickness)
00081               // Both images have to be border-resized.
00082               {
00083                 border::resize(ima1, min_thickness);
00084                 border::resize(ima2, min_thickness);
00085               }
00086             else
00087               // A single image has to be border-resized with
00088               // the other image thickness.
00089               if (b1 < min_thickness)
00090                 {
00091                   mln_assertion(b2 >= min_thickness);
00092                   border::resize(ima1, b2);
00093                 }
00094               else
00095                 {
00096                   //mln_assertion(b2 < min_thickness); // why ?
00097                   mln_assertion(b1 >= min_thickness);
00098                   border::resize(ima2, b1);
00099                 }
00100           }
00101 
00102         trace::exiting("border::impl::equalize_");
00103       }
00104 
00105     } // end of namespace mln::border::impl
00106 
00107 
00108     // Facade
00109 
00110     template <typename I, typename J>
00111     inline
00112     void equalize(const Image<I>& ima1_, const Image<J>& ima2_,
00113                   unsigned min_thickness)
00114     {
00115       trace::entering("border::equalize");
00116 
00117       //FIXME: check border
00118       //mlc_is(mln_trait_image_border(I), trait::image::border::some)::check();
00119       //mlc_is(mln_trait_image_border(J), trait::image::border::some)::check();
00120       const I& ima1 = exact(ima1_);
00121       const J& ima2 = exact(ima2_);
00122       mln_precondition(ima1.is_valid() && ima2.is_valid());
00123 
00124       impl::equalize_(ima1, ima2, min_thickness);
00125 
00126       mln_postcondition(border::get(ima1) == border::get(ima2) &&
00127                         border::get(ima1) >= min_thickness &&
00128                         border::get(ima2) >= min_thickness);
00129 
00130       trace::exiting("border::equalize");
00131     }
00132 
00133 # endif // ! MLN_INCLUDE_ONLY
00134 
00135   } // end of namespace mln::border
00136 
00137 } // end of namespace mln
00138 
00139 
00140 #endif // ! MLN_BORDER_EQUALIZE_HH

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