Fawkes API  Fawkes Development Version
shape_remover.cpp
1 
2 /***************************************************************************
3  * shape_remover.cpp - Implementation of a shape remover
4  *
5  * Created: Wed Sep 28 11:26:58 2005
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 <fvfilters/shape_remover.h>
25 
26 
27 #include <fvmodels/shape/shapemodel.h>
28 
29 namespace firevision {
30 #if 0 /* just to make Emacs auto-indent happy */
31 }
32 #endif
33 
34 /** @class FilterShapeRemover <fvfilters/shape_remover.h>
35  * Remove shapes from an image.
36  */
37 
38 /** Constructor. */
40  : Filter("FilterShapeRemover")
41 {
42  shape = NULL;
43 }
44 
45 
46 void
48 {
49  /* Code to remove lines here
50  * INPUT: Pre-filtered image or part of image that has clear edges set (white
51  * value at edge > 240)
52  * OUTPUT: the edges close to the given shape have been removed
53  */
54 
55  if (shape == NULL) return;
56 
57  shape->setMargin( margin );
58 
59  unsigned char *buffer = src_roi[0]->get_roi_buffer_start( src[0] );
60  unsigned char *linestart = buffer;
61 
62  if ( (dst == NULL) || (src[0] == dst) ) {
63 
64  for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
65 
66  for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
67  if ((*buffer > 240) && (shape->isClose(w, h))) {
68  *buffer = 0;
69  }
70  buffer++;
71  }
72 
73  linestart += src_roi[0]->line_step;
74  buffer = linestart;
75  }
76  } else {
77  unsigned char *dst_buffer = dst_roi->get_roi_buffer_start( dst );
78  unsigned char *dst_linestart = dst_buffer;
79 
80  for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
81 
82  for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
83  if ((*buffer > 240) && (shape->isClose(w, h))) {
84  *dst_buffer = 0;
85  } else {
86  *dst_buffer = *buffer;
87  }
88  buffer++;
89  dst_buffer++;
90  }
91 
92  linestart += src_roi[0]->line_step;
93  dst_linestart += dst_roi->line_step;
94  buffer = linestart;
95  dst_buffer = dst_linestart;
96  }
97  }
98 }
99 
100 
101 /** Set margin.
102  * @param margin margin around shape to be close to a point.
103  */
104 void
105 FilterShapeRemover::set_margin( unsigned int margin )
106 {
107  this->margin = margin;
108 }
109 
110 
111 /** Set shape that is to be removed.
112  * @param shape shape to remove
113  */
114 void
116 {
117  this->shape = shape;
118 }
119 
120 } // end namespace firevision
virtual bool isClose(unsigned int in_roi_x, unsigned int in_roi_y)=0
Check if the given point is close to the shape.
unsigned int width
ROI width.
Definition: roi.h:121
virtual void setMargin(unsigned int margin)=0
Set margin around shape.
virtual void set_shape(Shape *shape)
Set shape that is to be removed.
virtual void apply()
Apply the filter.
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
Filter interface.
Definition: filter.h:35
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
unsigned char * get_roi_buffer_start(unsigned char *buffer) const
Get ROI buffer start.
Definition: roi.cpp:556
unsigned int height
ROI height.
Definition: roi.h:123
unsigned int line_step
line step
Definition: roi.h:129
virtual void set_margin(unsigned int margin)
Set margin.
unsigned char * dst
Destination buffer.
Definition: filter.h:67
Shape interface.
Definition: shapemodel.h:39
ROI * dst_roi
Destination ROI.
Definition: filter.h:72