erode.hpp 2.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef MLN_MORPHO_STRUCTURAL_ERODE_HPP
# define MLN_MORPHO_STRUCTURAL_ERODE_HPP

# include <mln/morpho/canvas/dilation_like.hpp>
# include <mln/accu/accumulators/h_infsup.hpp>
# include <mln/accu/accumulators/infsup.hpp>

/// \file

namespace mln
{
  namespace morpho
  {
    namespace structural
    {

      /// \brief Dilation by a structuring element
      /// \param ima Input image
      /// \param se Structuring element
      /// \param cmp Comparaison function
      ///
      template <class I, class SE,
                class Compare = productorder_less<mln_value(I)> >
      mln_concrete(I)
      erode(const Image<I>& ima,
            const StructuringElement<SE>& nbh,
            Compare cmp = Compare ());

      template <class I, class SE, class OutputImage,
                class Compare = productorder_less<mln_value(I)> >
      OutputImage&
      erode(const Image<I>& ima,
            const StructuringElement<SE>& nbh,
            Image<OutputImage>& output,
            Compare cmp = Compare ());

      /******************************************/
      /****          Implementation          ****/
      /******************************************/


      namespace internal
      {

        template <class I, class SE, class Compare>
        struct erode_traits
        {
          using support_incremental = std::integral_constant<
            bool,
            std::is_integral<mln_value(I)>::value and
            std::is_same<Compare, productorder_less<mln_value(I)> >::value and
52
            (value_traits<mln_value(I)>::quant <= 16)
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            >;

          using aggregate_type      = accu::accumulators::inf<mln_value(I), Compare>;
          using incremental_aggregate_type = accu::accumulators::h_inf<mln_value(I)>;


          static
          constexpr
          mln_value(I) zero()
          {
            return value_traits<mln_value(I), Compare>::sup();
          }
        };

      }

      template <class I, class SE, class OutputImage,
                class Compare>
      OutputImage&
      erode(const Image<I>& ima,
            const StructuringElement<SE>& nbh,
            Image<OutputImage>& output,
            Compare cmp)
      {
        mln_entering("mln::morpho::structural::erode");

        morpho::canvas::dilation_like(ima, nbh, cmp, output, internal::erode_traits<I, SE, Compare> ());

        mln_exiting();
        return exact(output);
      }

      template <class I, class SE, class Compare>
      mln_concrete(I)
      erode(const Image<I>& ima,
             const StructuringElement<SE>& nbh,
             Compare cmp)
      {
        mln_concrete(I) out = imconcretize(exact(ima));
        erode(ima, nbh, out, cmp);
        return out;
      }



    } // end of namespace mln::morpho::structural
  } // end of namespace mln::morpho
} // end of namespace mln

#endif //!MLN_MORPHO_STRUCTURAL_ERODE_HPP