Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * border_shrinker.cpp - Implementation of BorderShrinker 00004 * 00005 * Generated: Wed Feb 15 2005 15:02:56 00006 * Copyright 2005-2006 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <classifiers/border_shrinker.h> 00025 00026 #include <fvutils/color/colorspaces.h> 00027 #include <fvutils/base/roi.h> 00028 00029 #include <models/scanlines/scanlinemodel.h> 00030 #include <models/color/colormodel.h> 00031 00032 #include <cstddef> 00033 00034 namespace firevision { 00035 #if 0 /* just to make Emacs auto-indent happy */ 00036 } 00037 #endif 00038 00039 /** @class BorderShrinker <classifiers/border_shrinker.h> 00040 * Border shrinker. 00041 * This shrinker makes sure that a ROI does not get too close to the image 00042 * boundaries. This may be needed for some mask-based operations. 00043 * 00044 */ 00045 00046 /** Constructor. 00047 * @param border_left minimum x value for ROI 00048 * @param border_right maximum x plus width value for ROI 00049 * @param border_top minimum y value for ROI 00050 * @param border_bottom maximum y plus height value for ROI 00051 */ 00052 BorderShrinker::BorderShrinker(unsigned int border_left, unsigned int border_right, 00053 unsigned int border_top, unsigned int border_bottom) 00054 : Shrinker() 00055 { 00056 src = NULL; 00057 this->border_left = border_left; 00058 this->border_right = border_right; 00059 this->border_top = border_top; 00060 this->border_bottom = border_bottom; 00061 } 00062 00063 00064 /** Virtual empty destructor. */ 00065 BorderShrinker::~BorderShrinker() 00066 { 00067 } 00068 00069 00070 /** Shrink! 00071 * Do the actual shrinking. 00072 * @param roi ROI to shrink 00073 */ 00074 void 00075 BorderShrinker::shrink( ROI *roi ) 00076 { 00077 unsigned int brdr; // border 00078 00079 // bottom 00080 if (border_bottom > 0) { 00081 brdr = roi->image_height - border_bottom; 00082 if (roi->start.y >= brdr) { 00083 roi->height = 0; 00084 } else if ((roi->start.y + roi->height) > brdr) { 00085 roi->height -= (roi->start.y + roi->height) - brdr; 00086 } 00087 } 00088 00089 // top 00090 if (border_top > 0) { 00091 brdr = border_top; 00092 if (roi->start.y <= brdr) { 00093 roi->height = 0; 00094 } else if ((roi->start.y + roi->height) < brdr) { 00095 roi->start.y = brdr; 00096 roi->height -= (roi->start.y + roi->height) - brdr; 00097 } 00098 } 00099 00100 // right 00101 if (border_right > 0) { 00102 brdr = roi->image_width - border_right; 00103 if (roi->start.x >= brdr) { 00104 roi->width = 0; 00105 } else if ((roi->start.x + roi->width) > brdr) { 00106 roi->width -= (roi->start.x + roi->width) - brdr; 00107 } 00108 } 00109 00110 // left 00111 if (border_left > 0) { 00112 brdr = border_left; 00113 if (roi->start.x <= brdr) { 00114 roi->width = 0; 00115 } else if ((roi->start.x + roi->width) < brdr) { 00116 roi->start.x = brdr; 00117 roi->width -= (roi->start.x + roi->width) - brdr; 00118 } 00119 } 00120 00121 } 00122 00123 } // end namespace firevision