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