Fawkes API Fawkes Development Version
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#include <fvfilters/difference.h>
26#include <fvfilters/morphology/closing.h>
27#include <fvfilters/morphology/segenerator.h>
28#include <fvfilters/morphology/tophat_closing.h>
29
30#include <cstddef>
31
32namespace firevision {
33
34/** Image that we subtract from */
35const unsigned int FilterTophatClosing::SUBTRACTFROM = 0;
36/** Image to filter. */
37const unsigned int FilterTophatClosing::FILTERIMAGE = 1;
38
39#define ERROR(m) \
40 { \
41 fawkes::Exception e("FilterTophatClosing failed"); \
42 e.append("Function: %s", __FUNCTION__); \
43 e.append("Message: %s", m); \
44 throw e; \
45 }
46
47/** @class FilterTophatClosing <fvfilters/morphology/tophat_closing.h>
48 * Morphological tophat closing.
49 * @author Tim Niemueller
50 */
51
52/** Constructor. */
54{
55 closing = new FilterClosing();
56 diff = new FilterDifference();
57
58 src[SUBTRACTFROM] = src[FILTERIMAGE] = dst = NULL;
60}
61
62/** Destructor. */
64{
65 delete closing;
66 delete diff;
67}
68
69void
71{
72 if (dst == NULL)
73 ERROR("dst == NULL");
74 if (src[SUBTRACTFROM] == NULL)
75 ERROR("src[SUBTRACTFROM] == NULL");
76 if (src[FILTERIMAGE] == NULL)
77 ERROR("src[FILTERIMAGE] == NULL");
79 ERROR("marker and mask ROI differ");
80
82
84 closing->set_dst_buffer(dst, dst_roi);
85
87 diff->set_src_buffer(dst, dst_roi, 0);
89
90 closing->apply();
91 diff->apply();
92}
93
94} // end namespace firevision
Morphological closing.
Definition: closing.h:35
virtual void set_src_buffer(unsigned char *buf, ROI *roi, orientation_t ori=ORI_HORIZONTAL, unsigned int buffer_num=0)
Set source buffer with orientation.
Definition: closing.cpp:53
virtual void set_dst_buffer(unsigned char *buf, ROI *roi)
Set the destination buffer.
Definition: closing.cpp:70
virtual void set_structuring_element(unsigned char *se, unsigned int se_width, unsigned int se_height, unsigned int se_anchor_x, unsigned int se_anchor_y)
Set the structuring element for successive filter runs.
Definition: closing.cpp:78
virtual void apply()
Apply the filter.
Definition: closing.cpp:90
Calculates the difference of two images.
Definition: difference.h:32
virtual void apply()
Apply the filter.
Definition: difference.cpp:41
static const unsigned int FILTERIMAGE
Image to filter.
virtual void apply()
Apply the filter.
virtual ~FilterTophatClosing()
Destructor.
static const unsigned int SUBTRACTFROM
Image that we subtract from.
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
virtual void set_dst_buffer(unsigned char *buf, ROI *roi)
Set the destination buffer.
Definition: filter.cpp:123
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
unsigned char * dst
Destination buffer.
Definition: filter.h:63
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
virtual void set_src_buffer(unsigned char *buf, ROI *roi, orientation_t ori=ORI_HORIZONTAL, unsigned int buffer_num=0)
Set source buffer with orientation.
Definition: filter.cpp:89
Morphological filter interface.
unsigned int se_height
Height of structuring element.
unsigned int se_width
Width of structuring element.
unsigned int se_anchor_y
Anchor point y offset of structuring element.
unsigned char * se
Structuring element.
unsigned int se_anchor_x
Anchor point x offset of structuring element.