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