ChangeLog | 10 ++
oln/morpho/hit_or_miss.hh | 14 +--
oln/morpho/top_hat.hh | 190 +++++++++++++++++++++++++++++++++++++++++++++
tests/morpho/tests/top_hat | 55 +++++++++++++
4 files changed, 262 insertions(+), 7 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add top-hat operators.
* oln/morpho/top_hat.hh: New file.
* tests/morpho/tests/top_hat: New test.
* olena/oln/morpho/hit_or_miss.hh: Add missing Doxygen tags in
comments.
2005-07-08 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/morpho/tests/top_hat
--- olena/tests/morpho/tests/top_hat (révision 0)
+++ olena/tests/morpho/tests/top_hat (révision 0)
@@ -0,0 +1,55 @@
+ // -*- C++ -*-
+#include "data.hh"
+#include <oln/utils/md5.hh>
+
+#include <ntg/int.hh>
+#include <oln/io/read_image.hh>
+#include <oln/basics2d.hh>
+#include <oln/morpho/top_hat.hh>
+
+using namespace oln;
+
+bool check()
+{
+ image2d<ntg::int_u8> ima;
+ ima = io::read(rdata("lena-small.pgm"));
+
+ // White top-hat.
+ utils::key::value_type data_key_wth[16] =
+ { 0x59, 0x93, 0x51, 0xde, 0x4, 0x43, 0xb8, 0x7e,
+ 0xf8, 0xf4, 0xd1, 0x7, 0x6c, 0x81, 0x2b, 0xb4 };
+ utils::key key_wth(data_key_wth);
+
+ if (utils::md5(morpho::white_top_hat(ima, win_c8p())) != key_wth)
+ return true;
+
+ // Black top-hat.
+ utils::key::value_type data_key_bth[16] =
+ {0x8e, 0xe6, 0x26, 0x8e, 0x80, 0x8d, 0xcc, 0x9e,
+ 0x35, 0x1e, 0xe5, 0x2b, 0x41, 0xb1, 0xde, 0x53 };
+ utils::key key_bth(data_key_bth);
+
+ if (utils::md5(morpho::black_top_hat(ima, win_c8p())) != key_bth)
+ return true;
+
+ // Self-complementary top-hat.
+ utils::key::value_type data_key_scth[16] =
+ { 0x50, 0xec, 0xca, 0x22, 0xce, 0xa4, 0x45, 0x32,
+ 0x52, 0x7b, 0x47, 0x4a, 0x4a, 0xe4, 0x8, 0x45 };
+ utils::key key_scth(data_key_scth);
+
+ if (utils::md5(morpho::self_complementary_top_hat(ima, win_c8p())) !=
+ key_scth)
+ return true;
+
+ // Top-hat contrast operator.
+ utils::key::value_type data_key_thco[16] =
+ { 0x6d, 0x4, 0x75, 0xf5, 0xb0, 0x79, 0xba, 0xe8,
+ 0x8e, 0x81, 0x69, 0x37, 0xf4, 0xbe, 0x27, 0x2d };
+ utils::key key_thco(data_key_thco);
+
+ if (utils::md5(morpho::top_hat_contrast_op(ima, win_c8p())) != key_thco)
+ return true;
+
+ return false;
+}
Index: olena/oln/morpho/hit_or_miss.hh
--- olena/oln/morpho/hit_or_miss.hh (révision 239)
+++ olena/oln/morpho/hit_or_miss.hh (copie de travail)
@@ -117,7 +117,7 @@
/*! \brief Perform an hit-or-miss opening.
- Compute the hit-or-miss opening of input by the composite
+ Compute the hit-or-miss opening of \a input by the composite
structuring element (win1, win2).
REF: Soille, 2nd ed., p.149.
@@ -153,7 +153,7 @@
/*! \brief Perform an hit-or-miss opening of background.
- Compute the hit-or-miss opening of the background of input by
+ Compute the hit-or-miss opening of the background of \a input by
the composite structuring element (win1, win2).
REF: Soille, 2nd ed., p.149.
@@ -189,7 +189,7 @@
/*! \brief Perform an hit-or-miss closing.
- Compute the hit-or-miss closing of input by the composite
+ Compute the hit-or-miss closing of \a input by the composite
structuring element (win1, win2). This is the dual
transformation of hit-or-miss opening with respect to set
complementation.
@@ -229,10 +229,10 @@
/*! \brief Perform an hit-or-miss closing of the background.
- Compute the hit-or-miss closing of the background of input by
- the composite structuring element (win1, win2). This is the
- dual transformation of hit-or-miss opening of the background
- with respect to set complementation.
+ Compute the hit-or-miss closing of the background of \a input
+ by the composite structuring element (win1, win2). This is
+ the dual transformation of hit-or-miss opening of the
+ background with respect to set complementation.
REF: Soille, 2nd ed., p.149.
Index: olena/oln/morpho/top_hat.hh
--- olena/oln/morpho/top_hat.hh (révision 0)
+++ olena/oln/morpho/top_hat.hh (révision 0)
@@ -0,0 +1,190 @@
+// Copyright (C) 2002, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_MORPHO_TOP_HAT_HH
+# define OLENA_MORPHO_TOP_HAT_HH
+
+# include <mlc/cmp.hh>
+
+# include <oln/utils/record.hh>
+# include <oln/morpho/opening.hh>
+# include <oln/morpho/closing.hh>
+# include <oln/morpho/temp.hh>
+# include <oln/level/arith.hh>
+
+// FIXME: More documentation (in particular, code snippets). See Olena
+// 0.10's doc.
+
+namespace oln {
+
+ namespace morpho {
+
+ /*! \brief Compute the white top-hat of an image (also called
+ top-hat by opening).
+
+ Compute white top-hat of \a input using \a win as structuring
+ element.
+
+ REF: Soille, 2nd ed., p.121.
+
+ \arg \c I exact type of the input image.
+ \arg \c W exact type of the first structuring element.
+
+ \param input image to process.
+ \param win structuring element. */
+ template<typename I, typename W>
+ oln_type_of(I, concrete)
+ white_top_hat(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::white_top_hat");
+ registering(input, "input");
+ oln_type_of(I, concrete) open("open"), output("output");
+
+ open = opening(input, win);
+ output = force_value_type_to<oln_type_of(I, concrete)>(input - open);
+
+ exiting("morpho::white_top_hat");
+ return output;
+ }
+
+ /*! \brief Compute the black top-hat of an image (also called
+ top-hat by closing).
+
+ Compute black top-hat of \a input using \a win as structuring
+ element.
+
+ REF: Soille, 2nd ed., p.122.
+
+ \arg \c I exact type of the input image.
+ \arg \c W exact type of the first structuring element.
+
+ \param input image to process.
+ \param win structuring element. */
+ template<typename I, typename W>
+ oln_type_of(I, concrete)
+ black_top_hat(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::black_top_hat");
+ registering(input, "input");
+ oln_type_of(I, concrete) close("close"), output("output");
+
+ close = closing(input, win);
+ output = force_value_type_to<oln_type_of(I, concrete)>(close - input);
+
+ exiting("morpho::black_top_hat");
+ return output;
+ }
+
+ /*! \brief Compute the self-complementary top-hat of an image.
+
+ Compute self-complementary top-hat of \a input using \a win as
+ structuring element.
+
+ REF: Soille, 2nd ed., p.122.
+
+ \arg \c I exact type of the input image.
+ \arg \c W exact type of the first structuring element.
+
+ \param input image to process.
+ \param win structuring element. */
+ template<typename I, typename W>
+ oln_type_of(I, concrete)
+ self_complementary_top_hat(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::self_complementary_top_hat");
+ registering(input, "input");
+ oln_type_of(I, concrete) close("close"), open("open"),
output("output");
+
+ close = closing(input, win);
+ open = opening(input, win);
+ output = force_value_type_to<oln_type_of(I, concrete)>(close - open);
+
+ exiting("morpho::self_complementary_top_hat");
+ return output;
+ }
+
+ /*! \brief Top-hat contrast operator.
+
+ Enhance contrast of \a input by adding the white top-hat, then
+ subtracting the black top-hat to \a input. Top-hats are
+ computed using \win as structuring element.
+
+ REF: Soille, 2nd ed., p.126.
+
+ \arg \c I exact type of the input image.
+ \arg \c W exact type of the first structuring element.
+
+ \param input image to process.
+ \param win structuring element. */
+ template<typename I, typename W>
+ oln_type_of(I, concrete)
+ top_hat_contrast_op(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::top_hat_contrast_op");
+ registering(input, "input");
+ oln_type_of(I, concrete) wth("wth"), bth("bth"),
output("output");
+
+ wth = white_top_hat(input, win);
+ bth = black_top_hat(input, win);
+ /* FIXME: A more efficient computation might be achieved using
+ this formula:
+
+ output =
+ force_value_type_to<oln_type_of(I, concrete)>
+ (3 * input + closing(input, win) - opening(input, win));
+
+ but we don't have the product of image with a literal yet in
+ Olena. */
+ /* FIXME: `force' is not necessary the preferred behavior.
+ Consider adding another facade to this operator, to let the
+ user choose another behavior (`bound', for example). See
+ Olena 0.10's oln/morpho/top_hat.inc. */
+ output =
+ force_value_type_to<oln_type_of(I, concrete)>(input + wth - bth);
+
+ exiting("morpho::top_hat_contrast_op");
+ return output;
+ }
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_TOP_HAT_HH