border_shrinker.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 BorderShrinker::BorderShrinker(unsigned int border_left, unsigned int border_right,
00048 unsigned int border_top, unsigned int border_bottom)
00049 : Shrinker()
00050 {
00051 src = NULL;
00052 this->border_left = border_left;
00053 this->border_right = border_right;
00054 this->border_top = border_top;
00055 this->border_bottom = border_bottom;
00056 }
00057
00058
00059
00060 BorderShrinker::~BorderShrinker()
00061 {
00062 }
00063
00064
00065
00066
00067
00068
00069 void
00070 BorderShrinker::shrink( ROI *roi )
00071 {
00072 unsigned int brdr;
00073
00074
00075 if (border_bottom > 0) {
00076 brdr = roi->image_height - border_bottom;
00077 if (roi->start.y >= brdr) {
00078 roi->height = 0;
00079 } else if ((roi->start.y + roi->height) > brdr) {
00080 roi->height -= (roi->start.y + roi->height) - brdr;
00081 }
00082 }
00083
00084
00085 if (border_top > 0) {
00086 brdr = border_top;
00087 if (roi->start.y <= brdr) {
00088 roi->height = 0;
00089 } else if ((roi->start.y + roi->height) < brdr) {
00090 roi->start.y = brdr;
00091 roi->height -= (roi->start.y + roi->height) - brdr;
00092 }
00093 }
00094
00095
00096 if (border_right > 0) {
00097 brdr = roi->image_width - border_right;
00098 if (roi->start.x >= brdr) {
00099 roi->width = 0;
00100 } else if ((roi->start.x + roi->width) > brdr) {
00101 roi->width -= (roi->start.x + roi->width) - brdr;
00102 }
00103 }
00104
00105
00106 if (border_left > 0) {
00107 brdr = border_left;
00108 if (roi->start.x <= brdr) {
00109 roi->width = 0;
00110 } else if ((roi->start.x + roi->width) < brdr) {
00111 roi->start.x = brdr;
00112 roi->width -= (roi->start.x + roi->width) - brdr;
00113 }
00114 }
00115
00116 }