make_edge_image.hh 3.01 KB
Newer Older
1
// Copyright (C) 2009, 2013 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
6
7
8
9
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
10
11
12
13
14
// 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
15
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
16
17
//
// As a special exception, you may use this file as part of a free
18
// software project without restriction.  Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
21
22
23
24
// 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.
25
26
27
28

#ifndef MLN_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH
# define MLN_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH

29
/// \file
30
31
32
///
/// Construct a valued image of edges.

33
# include <mln/core/image/image2d.hh>
34
35
# include <mln/core/image/dmorph/extension_ima.hh>
# include <mln/core/image/dmorph/image_if.hh>
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

# include <mln/core/routine/extend.hh>

# include <mln/world/inter_pixel/neighb2d.hh>
# include <mln/world/inter_pixel/dim2/is_edge.hh>
# include <mln/data/fill.hh>

namespace mln
{

  namespace world
  {

    namespace inter_pixel
    {

      namespace dim2
      {

	template <typename I, typename F>
	mln_concrete(I)
	make_edge_image(const Image<I>& input_, const Function_vv2v<F>& f_)
	{
	  trace::entering("world::inter_pixel::dim2::make_edge_image");

	  const I& input = exact(input_);
	  const F& f = exact(f_);
	  mln_precondition(input.is_valid());

	  typedef image_if<const image2d<value::int_u<8u> >,
			   world::inter_pixel::dim2::is_edge> edges_t;
	  edges_t edges =  input | is_edge();
	  typedef extension_ima<const edges_t,const I> edges_ext_t;
	  edges_ext_t edges_ext = extend(edges, input);

	  mln_piter(edges_ext_t) p(edges_ext.domain());
72
	  dbl_neighb2d nbh = e2v();
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
103
	  mln_niter(dbl_neighb2d) n(nbh, p);
	  mln_value(I) vs[2];

	  mln_concrete(I) output;
	  initialize(output, input);
	  data::fill(output, literal::zero);

	  for_all(p)
	  {
	    unsigned i = 0;
	    for_all(n)
	    {
	      mln_assertion(i < 2);
	      vs[i++] = input(n);
	    }
	    output(p) = f(vs[0], vs[1]);
	  }

	  trace::exiting("world::inter_pixel::dim2::make_edge_image");
	  return output;
	}

      } // end of namespace mln::world::inter_pixel::dim2

    } // end of namespace mln::world::inter_pixel

  } // end of namespace mln::world

} // end of namespace mln

#endif // ! MLN_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH