Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
tophat_closing.cpp
1
2
/***************************************************************************
3
* tophat_closing.cpp - implementation of morphological tophat closing
4
*
5
* Created: Sat Jun 10 16:21:30 2006
6
* Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include <core/exception.h>
25
26
#include <fvfilters/morphology/tophat_closing.h>
27
#include <fvfilters/morphology/segenerator.h>
28
#include <fvfilters/morphology/closing.h>
29
#include <fvfilters/difference.h>
30
31
#include <cstddef>
32
33
namespace
firevision {
34
#if 0
/* just to make Emacs auto-indent happy */
35
}
36
#endif
37
38
/** Image that we subtract from */
39
const
unsigned
int
FilterTophatClosing::SUBTRACTFROM = 0;
40
/** Image to filter. */
41
const
unsigned
int
FilterTophatClosing::FILTERIMAGE = 1;
42
43
#define ERROR(m) { \
44
fawkes::Exception e("FilterTophatClosing failed"); \
45
e.append("Function: %s", __FUNCTION__); \
46
e.append("Message: %s", m); \
47
throw e; \
48
}
49
50
/** @class FilterTophatClosing <fvfilters/morphology/tophat_closing.h>
51
* Morphological tophat closing.
52
* @author Tim Niemueller
53
*/
54
55
/** Constructor. */
56
FilterTophatClosing::FilterTophatClosing()
57
:
MorphologicalFilter
(
"Morphological Tophat Closing"
)
58
{
59
closing =
new
FilterClosing
();
60
diff =
new
FilterDifference
();
61
62
src
[
SUBTRACTFROM
] =
src
[
FILTERIMAGE
] =
dst
= NULL;
63
src_roi
[
SUBTRACTFROM
] =
src_roi
[
FILTERIMAGE
] =
dst_roi
= NULL;
64
}
65
66
67
/** Destructor. */
68
FilterTophatClosing::~FilterTophatClosing
()
69
{
70
delete
closing;
71
delete
diff;
72
}
73
74
75
void
76
FilterTophatClosing::apply
()
77
{
78
if
(
dst
== NULL ) ERROR(
"dst == NULL"
);
79
if
(
src
[
SUBTRACTFROM
] == NULL ) ERROR(
"src[SUBTRACTFROM] == NULL"
);
80
if
(
src
[
FILTERIMAGE
] == NULL ) ERROR(
"src[FILTERIMAGE] == NULL"
);
81
if
( *(
src_roi
[
SUBTRACTFROM
]) != *(
src_roi
[
FILTERIMAGE
]) ) ERROR(
"marker and mask ROI differ"
);
82
83
closing->
set_structuring_element
(
se
,
se_width
,
se_height
,
se_anchor_x
,
se_anchor_y
);
84
85
closing->
set_src_buffer
(
src
[FILTERIMAGE],
src_roi
[FILTERIMAGE] );
86
closing->
set_dst_buffer
(
dst
,
dst_roi
);
87
88
diff->
set_src_buffer
(
src
[SUBTRACTFROM],
src_roi
[SUBTRACTFROM], 1 );
89
diff->
set_src_buffer
(
dst
,
dst_roi
, 0 );
90
diff->
set_dst_buffer
(
dst
,
dst_roi
);
91
92
closing->
apply
();
93
diff->
apply
();
94
}
95
96
}
// end namespace firevision
src
libs
fvfilters
morphology
tophat_closing.cpp
Generated by
1.8.3.1