Fawkes API  Fawkes Development Version
border_shrinker.cpp
1 
2 /***************************************************************************
3  * border_shrinker.cpp - Implementation of BorderShrinker
4  *
5  * Generated: Wed Feb 15 2005 15:02:56
6  * Copyright 2005-2006 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 <fvclassifiers/border_shrinker.h>
25 
26 #include <fvutils/color/colorspaces.h>
27 #include <fvutils/base/roi.h>
28 
29 #include <fvmodels/scanlines/scanlinemodel.h>
30 #include <fvmodels/color/colormodel.h>
31 
32 #include <cstddef>
33 
34 namespace firevision {
35 #if 0 /* just to make Emacs auto-indent happy */
36 }
37 #endif
38 
39 /** @class BorderShrinker <fvclassifiers/border_shrinker.h>
40  * Border shrinker.
41  * This shrinker makes sure that a ROI does not get too close to the image
42  * boundaries. This may be needed for some mask-based operations.
43  *
44  */
45 
46 /** Constructor.
47  * @param border_left minimum x value for ROI
48  * @param border_right maximum x plus width value for ROI
49  * @param border_top minimum y value for ROI
50  * @param border_bottom maximum y plus height value for ROI
51  */
52 BorderShrinker::BorderShrinker(unsigned int border_left, unsigned int border_right,
53  unsigned int border_top, unsigned int border_bottom)
54  : Shrinker()
55 {
56  src = NULL;
57  this->border_left = border_left;
58  this->border_right = border_right;
59  this->border_top = border_top;
60  this->border_bottom = border_bottom;
61 }
62 
63 
64 /** Virtual empty destructor. */
66 {
67 }
68 
69 
70 /** Shrink!
71  * Do the actual shrinking.
72  * @param roi ROI to shrink
73  */
74 void
76 {
77  unsigned int brdr; // border
78 
79  // bottom
80  if (border_bottom > 0) {
81  brdr = roi->image_height - border_bottom;
82  if (roi->start.y >= brdr) {
83  roi->height = 0;
84  } else if ((roi->start.y + roi->height) > brdr) {
85  roi->height -= (roi->start.y + roi->height) - brdr;
86  }
87  }
88 
89  // top
90  if (border_top > 0) {
91  brdr = border_top;
92  if (roi->start.y <= brdr) {
93  roi->height = 0;
94  } else if ((roi->start.y + roi->height) < brdr) {
95  roi->start.y = brdr;
96  roi->height -= (roi->start.y + roi->height) - brdr;
97  }
98  }
99 
100  // right
101  if (border_right > 0) {
102  brdr = roi->image_width - border_right;
103  if (roi->start.x >= brdr) {
104  roi->width = 0;
105  } else if ((roi->start.x + roi->width) > brdr) {
106  roi->width -= (roi->start.x + roi->width) - brdr;
107  }
108  }
109 
110  // left
111  if (border_left > 0) {
112  brdr = border_left;
113  if (roi->start.x <= brdr) {
114  roi->width = 0;
115  } else if ((roi->start.x + roi->width) < brdr) {
116  roi->start.x = brdr;
117  roi->width -= (roi->start.x + roi->width) - brdr;
118  }
119  }
120 
121 }
122 
123 } // end namespace firevision
fawkes::upoint_t start
ROI start.
Definition: roi.h:119
virtual void shrink(ROI *roi)
Shrink! Do the actual shrinking.
unsigned int y
y coordinate
Definition: types.h:36
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:121
Region of interest.
Definition: roi.h:58
virtual ~BorderShrinker()
Virtual empty destructor.
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:125
unsigned char * src
Source image buffer.
Definition: shrinker.h:46
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:127
Shrinker class to shrink ROIs.
Definition: shrinker.h:34
BorderShrinker(unsigned int border_left=0, unsigned int border_right=0, unsigned int border_top=0, unsigned int border_bottom=10)
CloseShrinker shrinks ROIs It will make sure that any ROI that passes it will NOT be in the border re...
unsigned int height
ROI height.
Definition: roi.h:123