degate  0.1.2
Public Member Functions | Private Member Functions | Private Attributes
degate::ZeroCrossingEdgeDetection Class Reference

#include <ZeroCrossingEdgeDetection.h>

Inheritance diagram for degate::ZeroCrossingEdgeDetection:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ZeroCrossingEdgeDetection (unsigned int min_x, unsigned int max_x, unsigned int min_y, unsigned int max_y, unsigned int median_filter_width=3, unsigned int blur_kernel_size=10, double sigma=0.5, unsigned int _min_d=1, unsigned int _max_d=10, double _edge_threshold=0.25, double _zero_threshold=0.4)
TileImage_GS_DOUBLE_shptr run (ImageBase_shptr img_in, TileImage_GS_DOUBLE_shptr probability_map, std::string const &directory)
TileImage_GS_DOUBLE_shptr run (ImageBase_shptr img_in, TileImage_GS_DOUBLE_shptr probability_map)

Private Member Functions

bool trace (TileImage_GS_DOUBLE_shptr edge_image, int _x, int _y, int inc_x, int inc_y, int *start_x, int *stop_x, int *start_y, int *stop_y, double *mag, double edge_threshold, double zero_threshold, unsigned int min_d, unsigned int max_d)
TileImage_GS_DOUBLE_shptr analyze_edge_image (TileImage_GS_DOUBLE_shptr edge_image, TileImage_GS_DOUBLE_shptr probability_map, unsigned int min_d, unsigned int max_d)
void overlay_result (TileImage_GS_DOUBLE_shptr zc, TileImage_GS_DOUBLE_shptr bg, std::string const &directory) const

Private Attributes

unsigned int min_d
unsigned int max_d
double edge_threshold
double zero_threshold

Detailed Description

Definition at line 29 of file ZeroCrossingEdgeDetection.h.


Constructor & Destructor Documentation

ZeroCrossingEdgeDetection::ZeroCrossingEdgeDetection ( unsigned int  min_x,
unsigned int  max_x,
unsigned int  min_y,
unsigned int  max_y,
unsigned int  median_filter_width = 3,
unsigned int  blur_kernel_size = 10,
double  sigma = 0.5,
unsigned int  _min_d = 1,
unsigned int  _max_d = 10,
double  _edge_threshold = 0.25,
double  _zero_threshold = 0.4 
)

Definition at line 28 of file ZeroCrossingEdgeDetection.cc.

                                                                             :
  EdgeDetection(min_x, max_x, min_y, max_y, median_filter_width, blur_kernel_size, sigma),
  min_d(_min_d),
  max_d(_max_d),
  edge_threshold(_edge_threshold),
  zero_threshold(_zero_threshold) {
  }

Member Function Documentation

TileImage_GS_DOUBLE_shptr ZeroCrossingEdgeDetection::analyze_edge_image ( TileImage_GS_DOUBLE_shptr  edge_image,
TileImage_GS_DOUBLE_shptr  probability_map,
unsigned int  min_d,
unsigned int  max_d 
) [private]

Definition at line 168 of file ZeroCrossingEdgeDetection.cc.

References edge_threshold, degate::EdgeDetection::get_border(), degate::EdgeDetection::get_height(), degate::EdgeDetection::get_width(), trace(), and zero_threshold.

Referenced by run().

                                                                                      {
  int start_x = 0, start_y = 0, stop_x = 0, stop_y = 0;
  unsigned x, y;
  double mag = 0;

  normalize<TileImage_GS_DOUBLE, TileImage_GS_DOUBLE>(edge_image, edge_image, -1, 1);

  TileImage_GS_DOUBLE_shptr out_image(new TileImage_GS_DOUBLE(get_width(), get_height()));

  for(y = get_border() ; y < edge_image->get_height() - get_border(); y++) {
    for(x = get_border(); x < edge_image->get_width() - get_border();) {

      if(trace(edge_image, x, y, 1, 0,
               &start_x, &stop_x, &start_y, &stop_y, &mag,
               edge_threshold, zero_threshold,
               min_d, max_d)) {
        out_image->set_pixel(start_x + (stop_x - start_x)/2, y, mag);
        x += (stop_x > start_x + 1) ? stop_x - start_x - 1 : stop_x - start_x;
      }
      else x++;
    }
  }

  for(x = get_border(); x < edge_image->get_width() - get_border(); x++) {
    for(y = get_border(); y < edge_image->get_height() - get_border();) {
      if(trace(edge_image, x, y, 0, 1,
               &start_x, &stop_x, &start_y, &stop_y, &mag,
               edge_threshold, zero_threshold, min_d, max_d)) {
        out_image->set_pixel(x, start_y + (stop_y - start_y)/2, mag);
        y += (stop_y > start_y + 1) ? stop_y - start_y -1 : stop_y - start_y;
      }
      else y++;
    }
  }


      /*
      for(x = get_border(); x < edge_image->get_width() - get_border(); x++) {
        for(y = get_border(); y < edge_image->get_height() - get_border(); y++) {
          if(trace(edge_image, x, y, 1, 1,
                   &start_x, &stop_x, &start_y, &stop_y, &mag,
                   edge_threshold, zero_threshold, sqrt(2*min_d*min_d), sqrt(2*max_d*max_d))) {
            int
              p_x = start_x + (stop_x - start_x)/2,
              p_y = start_y + (stop_y - start_y)/2;
            if(p_x >= 0 && p_y >= 0 && p_x < out_image->get_width() && p_y < out_image->get_height())
              out_image->set_pixel(p_x, p_y, mag);
          }
        }
      }


      for(x = get_border(); x < edge_image->get_width() - get_border(); x++) {
        for(y = get_border(); y < edge_image->get_height() - get_border(); y++) {
          if(trace(edge_image, x, y, -1, 1,
                   &start_x, &stop_x, &start_y, &stop_y, &mag,
                   edge_threshold, zero_threshold, sqrt(2*min_d*min_d), sqrt(2*max_d*max_d))) {
            int
              p_x = start_x + (stop_x - start_x)/2,
              p_y = start_y + (stop_y - start_y)/2;
            if(p_x >= 0 && p_y >= 0 && p_x < out_image->get_width() && p_y < out_image->get_height())
              out_image->set_pixel(p_x, p_y, mag);
          }
        }
      }
      */

  return out_image;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ZeroCrossingEdgeDetection::overlay_result ( TileImage_GS_DOUBLE_shptr  zc,
TileImage_GS_DOUBLE_shptr  bg,
std::string const &  directory 
) const [private]

Definition at line 240 of file ZeroCrossingEdgeDetection.cc.

References degate::EdgeDetection::get_height(), degate::EdgeDetection::get_width(), and degate::join_pathes().

                                                                                 {

  assert(bg != NULL && zc != NULL);

  if(bg != NULL && zc != NULL) {
    for(unsigned int y = 0; y < get_height(); y++)
      for(unsigned int x = 0; x < get_width(); x++) {
        if(zc->get_pixel(x, y) > 0)
          bg->set_pixel(x, y, -1);
      }
    //save_image<TileImage_RGBA>(join_pathes(directory, "overlay.tif"),  bg);
    save_normalized_image<TileImage_GS_DOUBLE>(join_pathes(directory, "overlay.tif"),  bg);
  }
}

Here is the call graph for this function:

TileImage_GS_DOUBLE_shptr ZeroCrossingEdgeDetection::run ( ImageBase_shptr  img_in,
TileImage_GS_DOUBLE_shptr  probability_map,
std::string const &  directory 
)

Definition at line 65 of file ZeroCrossingEdgeDetection.cc.

References degate::join_pathes(), and degate::EdgeDetection::set_directory().

Referenced by degate::WireMatching::run().

                                                                                     {
  set_directory(directory);
  assert(img_in != NULL);
  TileImage_GS_DOUBLE_shptr zero_cross_img = run(img_in, probability_map);
  assert(zero_cross_img != NULL);

  save_normalized_image<TileImage_GS_DOUBLE>(join_pathes(directory, "03_edge_zero_cross.tif"),
                                             zero_cross_img);

  /*
  overlay_result(zero_cross_img,
                 std::dynamic_pointer_cast<TileImage_GS_DOUBLE>(img_in),
                 directory);
  */
  return zero_cross_img;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file ZeroCrossingEdgeDetection.cc.

References analyze_edge_image(), degate::EdgeDetection::get_edge_image(), degate::EdgeDetection::get_height(), degate::EdgeDetection::get_width(), max_d, min_d, and degate::EdgeDetection::run_edge_detection().

                                                                          {

  run_edge_detection(img_in);
  TileImage_GS_DOUBLE_shptr edge_image = get_edge_image(probability_map);
  //TileImage_GS_DOUBLE_shptr edge_magnitude_image = get_edge_magnitude_image(probability_map);

  TileImage_GS_DOUBLE_shptr zero_cross_img =
    analyze_edge_image(edge_image, probability_map, min_d, max_d);

  TileImage_GS_DOUBLE_shptr zero_cross_img2(new TileImage_GS_DOUBLE(get_width(), get_height()));

  morphological_close<TileImage_GS_DOUBLE, TileImage_GS_DOUBLE>
    (zero_cross_img2, zero_cross_img, 3, 1, 3);

  thinning<TileImage_GS_DOUBLE>(zero_cross_img2);

  return zero_cross_img2;
}

Here is the call graph for this function:

bool ZeroCrossingEdgeDetection::trace ( TileImage_GS_DOUBLE_shptr  edge_image,
int  _x,
int  _y,
int  inc_x,
int  inc_y,
int *  start_x,
int *  stop_x,
int *  start_y,
int *  stop_y,
double *  mag,
double  edge_threshold,
double  zero_threshold,
unsigned int  min_d,
unsigned int  max_d 
) [private]

Definition at line 85 of file ZeroCrossingEdgeDetection.cc.

References zero_threshold.

Referenced by analyze_edge_image().

                                                                              {

  if(start_x == NULL || start_y == NULL ||
     stop_x == NULL || stop_y == NULL || mag == NULL) return false;

  enum STATE {BEFORE, POS_EDGE, NEG_EDGE, END};
  STATE s = BEFORE;
  int x = _x, y = _y;
  double max_pix = 0, min_pix = 0;

  while(s != END) {
    double p = edge_image->get_pixel(x, y);

    if(s == BEFORE && p >= edge_threshold) {
      max_pix = p;
      *start_x = x;
      *start_y = y;
      s = POS_EDGE;
    }

    else if(s == POS_EDGE) {
      if(p > max_pix) {
        *start_x = x;
        *start_y = y;
        max_pix = p;
      }
      if(p <= -edge_threshold) {
        *stop_x = x;
        *stop_y = y;
        min_pix = p;
        s = NEG_EDGE;
      }
    }
    else if(s == NEG_EDGE) {
      if(p < min_pix) {
        min_pix = p;
        *stop_x = x;
        *stop_y = y;
      }
      if(p >= 0 ||
         x > *stop_x || y > *stop_y) { // that is at least one step beyond the maximum

        unsigned int
          d_x = abs(*stop_x - *start_x),
          d_y = abs(*stop_y - *start_y);


        if( !((d_x > min_d && d_x < max_d) ||
              (d_y > min_d && d_y < max_d))) return false;

        s = END;                //
        *mag = sqrt(pow(max_pix,2) + pow(min_pix, 2));

        double p_center = edge_image->get_pixel(*start_x + (*stop_x - *start_x)/2,
                                                *start_y + (*stop_y - *start_y)/2);

        return fabs(p_center) < zero_threshold;

      }
    }
    x += inc_x;
    y += inc_y;
    
    assert(x >= 0);
    assert(y >= 0);
    
    if(unsigned(x) >= edge_image->get_width() ||
       unsigned(y) >= edge_image->get_height() ||
       x == 0 || y == 0) s = END;
  }
  return false;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 35 of file ZeroCrossingEdgeDetection.h.

Referenced by analyze_edge_image().

Definition at line 34 of file ZeroCrossingEdgeDetection.h.

Referenced by run().

Definition at line 33 of file ZeroCrossingEdgeDetection.h.

Referenced by run().

Definition at line 35 of file ZeroCrossingEdgeDetection.h.

Referenced by analyze_edge_image(), and trace().


The documentation for this class was generated from the following files: