dmap.hh

Go to the documentation of this file.
00001 // Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and
00002 // Development Laboratory
00003 //
00004 // This file is part of the Olena Library.  This library is free
00005 // software; you can redistribute it and/or modify it under the terms
00006 // of the GNU General Public License version 2 as published by the
00007 // Free Software Foundation.
00008 //
00009 // This library 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 this library; see the file COPYING.  If not, write to
00016 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017 // Boston, MA 02110-1301, USA.
00018 //
00019 // As a special exception, you may use this file as part of a free
00020 // software library without restriction.  Specifically, if other files
00021 // instantiate templates or use macros or inline functions from this
00022 // file, or you compile this file and link it with other files to
00023 // produce an executable, this file does not by itself cause the
00024 // resulting executable to be covered by the GNU General Public
00025 // License.  This exception does not however invalidate any other
00026 // reasons why the executable file might be covered by the GNU General
00027 // Public License.
00028 
00029 #ifndef OLENA_TOPO_DMAP_HH
00030 # define OLENA_TOPO_DMAP_HH
00031 
00032 # include <ntg/bin.hh>
00033 # include <oln/basics2d.hh>
00034 # include <oln/core/w_window2d.hh>
00035 
00036 // \todo FIXME: math.h should be included by ntg/config/system.hh
00037 // # include <math.h>
00038 # include <utility>
00039 
00046 namespace oln {
00047 
00049   namespace topo {
00055     template<class T>
00056     struct chamfer
00057     {
00058       chamfer(const w_window2d<T>& fwd,
00059               const w_window2d<T>& bkd,
00060               float coef);
00061 
00062       coord
00063       delta() const;
00064 
00065       const w_window2d<T> fwd;
00066       const w_window2d<T> bkd;
00067       const float coef;
00068     };
00069 
00088     template<int d10, int d11> inline
00089     const chamfer<int>&
00090     mk_chamfer_3x3(float coef = 1.f);
00091 
00110     inline
00111     const chamfer<float>&
00112     mk_chamfer_3x3(float d10, float d11);
00113 
00134     template<int d10, int d11, int d21> inline
00135     const chamfer<int>&
00136     mk_chamfer_5x5(float coef = 1.f);
00137 
00142     inline
00143     const chamfer<float>&
00144     mk_chamfer_5x5(float d10, float d11, float d21);
00145 
00162     inline const chamfer<int>& chamfer_1_1();
00163 
00180     inline const chamfer<int>& chamfer_1_2();
00197     inline const chamfer<int>& chamfer_2_3();
00214     inline const chamfer<int>& chamfer_5_7();
00231     inline const chamfer<int>& chamfer_12_17();
00248     inline const chamfer<int>& chessboard();
00265     inline const chamfer<int>& cityblock();
00286     inline const chamfer<int>& chamfer_4_6_9();
00307     inline const chamfer<int>& chamfer_5_7_11();
00328     inline const chamfer<int>& chamfer_9_13_20();
00349     inline const chamfer<int>& chamfer_16_23_36();
00366     inline const chamfer<float>& best_set_3x3();
00387     inline const chamfer<float>& best_set_5x5();
00388 
00389     // maximum absolute error for integer local distances (Table 2)
00390     /* Maximum absolute error for integer local distances for chamfer_1_1.
00391     **
00392     ** \verbatim
00393     ** oln::topo::mchamfer_1_1() =
00394     ** w.delta(): 1
00395     ** w.coef: 0.8536
00396     ** w.fwd:
00397     **  1  1  1
00398     **  1  .  .
00399     **  .  .  .
00400     ** w.bkd:
00401     **  .  .  .
00402     **  .  .  1
00403     **  1  1  1
00404     ** \endverbatim
00405     */
00406     inline const chamfer<int>& mchamfer_1_1();
00407     /* Maximum absolute error for integer local distances for chamfer_1_2.
00408     **
00409     ** \verbatim
00410     ** oln::topo::mchamfer_1_2() =
00411     ** w.delta(): 1
00412     ** w.coef: 1.2071
00413     ** w.fwd:
00414     **  2  1  2
00415     **  1  .  .
00416     **  .  .  .
00417     ** w.bkd:
00418     **  .  .  .
00419     **  .  .  1
00420     **  2  1  2
00421     ** \endverbatim
00422     */
00423     inline const chamfer<int>& mchamfer_1_2();
00424     /* Maximum absolute error for integer local distances for chamfer_2_3.
00425     **
00426     ** \verbatim
00427     ** oln::topo::mchamfer_2_3() =
00428     ** w.delta(): 1
00429     ** w.coef: 2.118
00430     ** w.fwd:
00431     **  3  2  3
00432     **  2  .  .
00433     **  .  .  .
00434     ** w.bkd:
00435     **  .  .  .
00436     **  .  .  2
00437     **  3  2  3
00438     ** \endverbatim
00439     */
00440     inline const chamfer<int>& mchamfer_2_3();
00441     /* Maximum absolute error for integer local distances for chamfer_5_7.
00442     **
00443     ** \verbatim
00444     ** oln::topo::mchamfer_5_7() =
00445     ** w.delta(): 1
00446     ** w.coef: 5.1675
00447     ** w.fwd:
00448     **  7  5  7
00449     **  5  .  .
00450     **  .  .  .
00451     ** w.bkd:
00452     **  .  .  .
00453     **  .  .  5
00454     **  7  5  7
00455     ** \endverbatim
00456     */
00457     inline const chamfer<int>& mchamfer_5_7();
00458     /* Maximum absolute error for integer local distances for chamfer_12_17.
00459     **
00460     ** \verbatim
00461     ** oln::topo::mchamfer_12_17() =
00462     ** w.delta(): 1
00463     ** w.coef: 12.5
00464     ** w.fwd:
00465     **  17  12  17
00466     **  12  .   .
00467     **  .   .   .
00468     ** w.bkd:
00469     **  .   .   .
00470     **  .   .   12
00471     **  17  12  17
00472     ** \endverbatim
00473     */
00474     inline const chamfer<int>& mchamfer_12_17();
00475     /* Maximum absolute error for integer local distances for chessboard.
00476     **
00477     ** \verbatim
00478     ** oln::topo::mchessboard() =
00479     ** w.delta(): 1
00480     ** w.coef: 0.8536
00481     ** w.fwd:
00482     **  1  1  1
00483     **  1  .  .
00484     **  .  .  .
00485     ** w.bkd:
00486     **  .  .  .
00487     **  .  .  1
00488     **  1  1  1
00489     ** \endverbatim
00490     */
00491     inline const chamfer<int>& mchessboard();
00492     /* Maximum absolute error for integer local distances for cityblock.
00493     **
00494     ** \verbatim
00495     ** oln::topo::mcityblock() =
00496     ** w.delta(): 1
00497     ** w.coef: 1.2071
00498     ** w.fwd:
00499     **  2  1  2
00500     **  1  .  .
00501     **  .  .  .
00502     ** w.bkd:
00503     **  .  .  .
00504     **  .  .  1
00505     **  2  1  2
00506     ** \endverbatim
00507     */
00508     inline const chamfer<int>& mcityblock();
00509     /* Maximum absolute error for integer local distances for chamfer_4_6_9.
00510     **
00511     ** \verbatim
00512     ** oln::topo::mchamfer_4_6_9() =
00513     ** w.delta(): 2
00514     ** w.coef: 4.1213
00515     ** w.fwd:
00516     **  .  9  .  9  .
00517     **  9  6  4  6  9
00518     **  .  4  .  .  .
00519     **  .  .  .  .  .
00520     **  .  .  .  .  .
00521     ** w.bkd:
00522     **  .  .  .  .  .
00523     **  .  .  .  .  .
00524     **  .  .  .  4  .
00525     **  9  6  4  6  9
00526     **  .  9  .  9  .
00527     ** \endverbatim
00528     */
00529     inline const chamfer<int>& mchamfer_4_6_9();
00530     /* Maximum absolute error for integer local distances for chamfer_5_7_11.
00531     **
00532     ** \verbatim
00533     ** oln::topo::mchamfer_5_7_11() =
00534     ** w.delta(): 2
00535     ** w.coef: 5.0092
00536     ** w.fwd:
00537     **  .   11  .   11   .
00538     **  11  7   5   7   11
00539     **  .   5   .   .   .
00540     **  .   .   .   .   .
00541     **  .   .   .   .   .
00542     ** w.bkd:
00543     **  .   .   .   .   .
00544     **  .   .   .   .   .
00545     **  .   .   .   5   .
00546     **  11  7   5   7   11
00547     **  .   11  .   11  .
00548     ** \endverbatim
00549     */
00550     inline const chamfer<int>& mchamfer_5_7_11();
00551     /* Maximum absolute error for integer local distances for chamfer_9_13_20.
00552     **
00553     ** \verbatim
00554     ** oln::topo::mchamfer_9_13_20() =
00555     ** w.delta(): 2
00556     ** w.coef: 9.0819
00557     ** w.fwd:
00558     **  .   20  .  20  .
00559     **  20  13  9  13  20
00560     **  .   9   .  .   .
00561     **  .   .   .  .   .
00562     **  .   .   .  .   .
00563     ** w.bkd:
00564     **  .   .   .  .   .
00565     **  .   .   .  .   .
00566     **  .   .   .  9   .
00567     **  20  13  9  13  20
00568     **  .   20  .  20  .
00569     ** \endverbatim
00570     */
00571     inline const chamfer<int>& mchamfer_9_13_20();
00572     /* Maximum absolute error for integer local distances for chamfer_17_24_38.
00573     **
00574     ** \verbatim
00575     ** oln::topo::mchamfer_17_24_38() =
00576     ** w.delta(): 2
00577     ** w.coef: 17.2174
00578     ** w.fwd:
00579     **  .   38  .   38  .
00580     **  38  24  17  24  38
00581     **  .   17  .   .   .
00582     **  .   .   .   .   .
00583     **  .   .   .   .   .
00584     ** w.bkd:
00585     **  .   .   .   .   .
00586     **  .   .   .   .   .
00587     **  .   .   .   17  .
00588     **  38  24  17  24  38
00589     **  .   38  .   38  .
00590     ** \endverbatim
00591     */
00592     inline const chamfer<int>& mchamfer_17_24_38();
00593     /* Maximum absolute error for integer local distances for best_set_3x3.
00594     **
00595     ** \verbatim
00596     ** oln::topo:mbest_set_3x3() =
00597     ** w.delta(): 1
00598     ** w.coef: 1
00599     ** w.fwd:
00600     **  1.35825  0.96043  1.35825
00601     **  0.96043  .  .
00602     **  .  .  .
00603     ** w.bkd:
00604     **  .  .  .
00605     **  .  .  0.96043
00606     **  1.35825  0.96043  1.35825
00607     ** \endverbatim
00608     */
00609     inline const chamfer<float>& mbest_set_3x3();
00610     /* Maximum absolute error for integer local distances for best_set_5x5.
00611     **
00612     ** \verbatim
00613     ** oln::topo:mbest_set_5x5() =
00614     ** w.delta(): 2
00615     ** w.coef: 1
00616     ** w.fwd:
00617     **  .  2.20585  .  2.20585  .
00618     **  2.20585  1.3951  0.986485  1.3951  2.20585
00619     **  .  0.986485  .  .  .
00620     **  .  .  .  .  .
00621     **  .  .  .  .  .
00622     ** w.bkd:
00623     **  .  .  .  .  .
00624     **  .  .  .  .  .
00625     **  .  .  .  0.986485  .
00626     **  2.20585  1.3951  0.986485  1.3951  2.20585
00627     **  .  2.20585  .  2.20585  .
00628     ** \endverbatim
00629     */
00630     inline const chamfer<float>& mbest_set_5x5();
00631 
00660     template<class T, class T2>
00661     class dmap
00662     {
00663     public:
00664       typedef image2d<ntg::bin>::point_type point_type;
00665 
00671       dmap(const image2d_size& size, const chamfer<T2>& ch);
00672 
00674       template <class V>
00675       void
00676       compute(const image2d<V>& input, float infty = 0.f);
00677 
00679       template <class V>
00680       void
00681       compute(const image2d<V>& input,
00682               image2d<point2d>& nearest_point_map,
00683               float             infty = 0.f);
00684 
00686       const image2d<T>&
00687       imap() const;
00688 
00690       image2d<float>
00691       to_image() const;
00692 
00694       const T
00695       operator[](const point_type& p) const;
00696 
00698       const T
00699       operator()(coord row, coord col) const;
00700 
00701     private:
00702       image2d<T>        imap_;
00703       chamfer<T2>       ch_;
00704       float             inFty_;
00705       T                 infTy_;
00706     };
00708     template <class I>
00709     image2d<float> exact_dmap(const abstract::image<I>& input);
00710 
00711   } // end of namespace topo
00712 
00713 } // end of namespace oln
00714 
00715 # include <oln/topo/dmap.hxx>
00716 
00717 #endif // OLENA_TOPO_DMAP_HH

Generated on Tue Feb 20 20:18:49 2007 for Olena by  doxygen 1.5.1