00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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           
00079           {
00080             if (b1 < min_thickness && b2 < min_thickness)
00081               
00082               {
00083                 border::resize(ima1, min_thickness);
00084                 border::resize(ima2, min_thickness);
00085               }
00086             else
00087               
00088               
00089               if (b1 < min_thickness)
00090                 {
00091                   mln_assertion(b2 >= min_thickness);
00092                   border::resize(ima1, b2);
00093                 }
00094               else
00095                 {
00096                   
00097                   mln_assertion(b1 >= min_thickness);
00098                   border::resize(ima2, b1);
00099                 }
00100           }
00101 
00102         trace::exiting("border::impl::equalize_");
00103       }
00104 
00105     } 
00106 
00107 
00108     
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       
00118       
00119       
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   } 
00136 
00137 } 
00138 
00139 
00140 #endif // ! MLN_BORDER_EQUALIZE_HH