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 
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. */
57  : MorphologicalFilter("Morphological Tophat Closing")
58 {
59  closing = new FilterClosing();
60  diff = new FilterDifference();
61 
62  src[SUBTRACTFROM] = src[FILTERIMAGE] = dst = NULL;
64 }
65 
66 
67 /** Destructor. */
69 {
70  delete closing;
71  delete diff;
72 }
73 
74 
75 void
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 
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
unsigned int se_anchor_y
Anchor point y offset of structuring element.
unsigned int se_anchor_x
Anchor point x offset of structuring element.
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:93
virtual void apply()
Apply the filter.
Definition: difference.cpp:46
virtual void set_dst_buffer(unsigned char *buf, ROI *roi)
Set the destination buffer.
Definition: closing.cpp:79
unsigned char * se
Structuring element.
Calculates the difference of two images.
Definition: difference.h:34
virtual ~FilterTophatClosing()
Destructor.
unsigned int se_height
Height of structuring element.
Morphological filter interface.
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
Morphological closing.
Definition: closing.h:37
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:88
static const unsigned int FILTERIMAGE
Image to filter.
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
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:62
unsigned int se_width
Width of structuring element.
virtual void apply()
Apply the filter.
Definition: closing.cpp:99
unsigned char * dst
Destination buffer.
Definition: filter.h:67
static const unsigned int SUBTRACTFROM
Image that we subtract from.
ROI * dst_roi
Destination ROI.
Definition: filter.h:72
virtual void apply()
Apply the filter.
virtual void set_dst_buffer(unsigned char *buf, ROI *roi)
Set the destination buffer.
Definition: filter.cpp:134