1 #include "ContourDetectorSimple.hh"
11 inline unsigned short mymin(
unsigned short a,
unsigned short b)
16 inline unsigned short min(
unsigned short s0,
22 return mymin(s0, mymin(s1, mymin(s2, mymin(s3, s4))));
26 template <
class StorageType>
33 template <
class StorageType> StorageType
37 return data[row][col];
40 template <
class StorageType>
void
42 Set(
int row,
int col, StorageType value)
44 data[row][col] = value;
55 #ifdef BUILD_IMAGE_INT
58 #ifdef BUILD_IMAGE_CHAR
61 #ifdef BUILD_IMAGE_SHORT
63 #ifdef BUILD_IMAGE_USHORT
66 #ifdef BUILD_IMAGE_UINT
68 #ifdef BUILD_IMAGE_DOUBLE
74 template <
class StorageType>
77 SetBackground(StorageType(0));
81 template <
class StorageType>
87 template <
class StorageType>
90 const std::vector<BIASContour> & contour){
92 if(contour.size() == 0 || contour[0].length ==0)
101 for (
unsigned int i=0;i<contour.size();i++){
103 for (
unsigned int k=0;k<contour[i].length;k++){
104 for (
unsigned int c=0;c<channels;c++){
105 if((
unsigned int)contour[i].contourPixel[k][0] > 0 && (
unsigned int)contour[i].contourPixel[k][0] < w &&
106 (
unsigned int)contour[i].contourPixel[k][1] > 0 && (
unsigned int)contour[i].contourPixel[k][1] < h){
107 ida[(
unsigned int)contour[i].contourPixel[k][1]]
108 [(
unsigned int)contour[i].contourPixel[k][0]*channels+c] = 255;
116 template <
class StorageType>
121 for (
int y = 0; y < img_h; y++)
122 for (
int x = 0; x < img_w; x++)
133 template <
class StorageType>
142 const int offset = img_w-1;
143 for (
int i = 0; i < img_h; i++) {
144 data_[i][0] = background_;
145 data_[i][offset] = background_;
148 for (
int n = 0; n < img_h; n += (img_h-1)) {
149 StorageType *line = data_[n];
150 for (
int i = 0; i < img_w; i++)
151 line[i] = background_;
156 template <
class StorageType>
159 std::vector<BIAS::BIASContour>& contour){
161 if(contour.size() < 1){
163 contour.push_back(cont);
168 CreateContourBase_(contour[0],image);
169 return contour[0].length;
174 template <
class StorageType>
179 InitDistanceImage_(dist_img, contour);
180 MakeDistanceImage_(dist_img);
183 template <
class StorageType>
190 bool ret = CreateContourBase_( contour, img );
192 if (contour.
length <= 0 || !ret)
195 CreateDistanceImage( dist_img, contour );
204 template <
class StorageType>
bool
214 ret = FindFirst_( first_x, first_y );
215 if ( first_x < 0 || first_y < 0 || !ret)
223 directionList_.clear();
234 while ( !IsFg_(x,y,d) && d < stop) {
238 directionList_.push_back (d);
241 case 0: x += 1; y += 0;
break;
242 case 1: x += 1; y += 1;
break;
243 case 2: x += 0; y += 1;
break;
244 case 3: x -= 1; y += 1;
break;
245 case 4: x -= 1; y += 0;
break;
246 case 5: x -= 1; y -= 1;
break;
247 case 6: x += 0; y -= 1;
break;
248 case 7: x += 1; y -= 1;
break;
250 }
while ( x != first_x || y != first_y );
256 template <
class StorageType>
265 for (
int i = 0; i < pixels; i++)
266 data[i] = numeric_limits<StorageType>::max();
269 for (
unsigned int i = 0; i < contour.
contourPixel.size(); i++)
276 template <
class StorageType>
288 for (
int k = 1; k <= rows-1; k++) {
289 for (
int j = 1; j <= cols-1-1; j++) {
290 min = numeric_limits<StorageType>::max();
291 if (min > d.
Get(k,j)) min = d.
Get(k,j);
292 if (min > d.
Get(k,j-1)+3) min = d.
Get(k,j-1)+3;
293 if (min > d.
Get(k-1,j)+3) min = d.
Get(k-1,j)+3;
294 if (min > d.
Get(k-1,j-1)+4) min = d.
Get(k-1,j-1)+4;
295 if (min > d.
Get(k-1,j+1)+4) min = d.
Get(k-1,j+1)+4;
301 for (
int k = rows-1-1; k >= 0; k--) {
302 for (
int j = cols-1-1; j >= 1; j--) {
303 min = numeric_limits<StorageType>::max();
304 if (min > d.
Get(k,j)) min = d.
Get(k,j);
305 if (min > d.
Get(k,j+1)+3) min = d.
Get(k,j+1)+3;
306 if (min > d.
Get(k+1,j)+3) min = d.
Get(k+1,j)+3;
307 if (min > d.
Get(k+1,j+1)+4) min = d.
Get(k+1,j+1)+4;
308 if (min > d.
Get(k+1,j-1)+4) min = d.
Get(k+1,j-1)+4;
323 #ifdef BUILD_IMAGE_INT
326 #ifdef BUILD_IMAGE_CHAR
329 #ifdef BUILD_IMAGE_SHORT
331 #ifdef BUILD_IMAGE_USHORT
334 #ifdef BUILD_IMAGE_UINT
336 #ifdef BUILD_IMAGE_DOUBLE
This class describes a contour using the freemancode.
std::vector< BIAS::Vector2< double > > contourPixel
All pixels contained in the contour.
unsigned int GetWidth() const
a class for calculating the contour of a segmented region
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
The image template class for specific storage types.
void SetPixel(const StorageType &value, const unsigned int &x, const unsigned int &y, const unsigned short int channel=0)
Set the value of a given pixel (x,y) in channel to value.
StorageType Get(int row, int col)
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void Set(int row, int col, StorageType value)
unsigned long int GetPixelCount() const
returns number of pixels in image
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase