lines_h_pattern.hh 3.35 KB
Newer Older
Guillaume Lazzara's avatar
Guillaume Lazzara committed
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
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// 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,
// 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 Olena.  If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project 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.

26
27
#ifndef SCRIBO_PRIMITIVE_EXTRACT_LINES_H_PATTERN_HH
# define SCRIBO_PRIMITIVE_EXTRACT_LINES_H_PATTERN_HH
Guillaume Lazzara's avatar
Guillaume Lazzara committed
28
29
30
31
32

/// \file
///
/// Extract horizontal lines matching a specific pattern.

Guillaume Lazzara's avatar
Guillaume Lazzara committed
33
34
35
# include <mln/core/concept/image.hh>
# include <mln/core/alias/window2d.hh>
# include <mln/win/rectangle2d.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
36
37
# include <mln/morpho/dilation.hh>

Guillaume Lazzara's avatar
Guillaume Lazzara committed
38
39
# include <mln/arith/times.hh>

40
# include <scribo/primitive/extract/lines_pattern.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
41

Guillaume Lazzara's avatar
Guillaume Lazzara committed
42
43
44
# include <scribo/primitive/internal/rd.hh>


Guillaume Lazzara's avatar
Guillaume Lazzara committed
45
46
47
namespace scribo
{

48
  namespace primitive
Guillaume Lazzara's avatar
Guillaume Lazzara committed
49
50
  {

51
    namespace extract
Guillaume Lazzara's avatar
Guillaume Lazzara committed
52
    {
53

Guillaume Lazzara's avatar
Guillaume Lazzara committed
54
55
      using namespace mln;

Guillaume Lazzara's avatar
Guillaume Lazzara committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
      /*! \brief Extract horizontal lines matching a specific pattern.

	\param[in] input  A binary image.
	\param[in] length The minimum line length.
	\param[in] delta Distance between the object pixel and the
	background pixel.

	\result An image of horizontal lines.


	     o
	     |     ^
	     |     |  Delta
	     |     v
	     X
	     |     ^
	     |     |  Delta
	     |     v
	     o

	Using a delta of 0 is equivalent to the use of a c2_row
	neighborhood.

      */
Guillaume Lazzara's avatar
Guillaume Lazzara committed
80
81
      template <typename I>
      mln_concrete(I)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
82
      lines_h_pattern(const Image<I>& input, unsigned length, unsigned delta);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
83
84
85
86
87
88


# ifndef MLN_INCLUDE_ONLY

      template <typename I>
      mln_concrete(I)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
89
      lines_h_pattern(const Image<I>& input, unsigned length, unsigned delta)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
90
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
91
92
	trace::entering("scribo::primitive::extract::lines_h_pattern");

Guillaume Lazzara's avatar
Guillaume Lazzara committed
93
94
95
	mlc_is(mln_value(I), bool)::check();
	mln_precondition(exact(input).is_valid());

Guillaume Lazzara's avatar
Guillaume Lazzara committed
96
97
98
	// FIXME: not generic.
 	window2d win;
	mln_deduce(I, site, dpsite)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
99
100
	  dp1(-delta - 1, 0),
	  dp2( delta + 1, 0);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
101
102
	win.insert(dp1);
	win.insert(dp2);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
103

Guillaume Lazzara's avatar
Guillaume Lazzara committed
104
105
106
107
108
109
110
111
112
113
	mln_concrete(I) output = lines_pattern(input, length, 1, win);

	mln_concrete(I)
	  output_dil = morpho::dilation(output,
					win::rectangle2d(3, length / 2 + delta));

	output = scribo::primitive::internal::rd(output, input * output_dil);

	trace::exiting("scribo::primitive::extract::lines_h_pattern");
	return output;
Guillaume Lazzara's avatar
Guillaume Lazzara committed
114
115
116
117
      }

# endif // ! MLN_INCLUDE_ONLY

118
    } // end of namespace scribo::primitive::extract
Guillaume Lazzara's avatar
Guillaume Lazzara committed
119

120
  } // end of namespace scribo::primitive
Guillaume Lazzara's avatar
Guillaume Lazzara committed
121

122
} // end of namespace scribo
Guillaume Lazzara's avatar
Guillaume Lazzara committed
123
124


125
#endif // ! SCRIBO_PRIMITIVE_EXTRACT_LINES_H_PATTERN_HH
Guillaume Lazzara's avatar
Guillaume Lazzara committed
126