contrib/oxl/osl/osl_canny_smooth.cxx
Go to the documentation of this file.
00001 // This is oxl/osl/osl_canny_smooth.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author fsm
00008 // see osl_canny_smooth.txx for template functions.
00009 
00010 #include "osl_canny_smooth.h"
00011 #include <vcl_cstdlib.h> // vcl_abort()
00012 #include <vcl_iostream.h>
00013 #include <vxl_config.h>
00014 #include <vil1/vil1_rgb.h>
00015 #include <vil1/vil1_pixel.h>
00016 #include <vil1/vil1_memory_image_of.h>
00017 
00018 #if 0
00019 #include <vil1/vil1_save.h>
00020 void debug_save(float const * const *image_out, int w, int h, char const *file) {
00021   vil1_memory_image_of<unsigned char> debug(w, h);
00022   for (unsigned i=0; i<h; ++i)
00023     for (unsigned j=0; j<w; ++j)
00024       debug[i][j] = (unsigned char) image_out[i][j];
00025   vcl_cerr << "save to " << file << vcl_endl;
00026   vil1_save(debug, file, "png");
00027 }
00028 #endif
00029 
00030 
00031 //"osl_canny_smooth.cxx", line 37: Error: Overloading ambiguity between
00032 // "osl_canny_smooth_rothwell<unsigned char>(const vil1_memory_image_of<unsigned char>&, const float*, int, int, float**)"
00033 // and
00034 // "osl_canny_smooth_rothwell<unsigned char>(const vil1_memory_image_of<unsigned char>&, const float*, int, int, float**)".
00035 
00036 void osl_canny_smooth_rothwell(vil1_image const &image_in,
00037                                float const *kernel_, int width_, int k_size_,
00038                                float * const *smooth_)
00039 {
00040   if (false) { }
00041 #define macro(pt, st) \
00042   else if (vil1_pixel_format(image_in) == pt) { \
00043     vil1_memory_image_of<st > sec(image_in); \
00044     osl_canny_smooth_rothwell(const_cast<st const *const*>(sec.row_array()), sec.height(), sec.width(), \
00045                               kernel_, width_, k_size_, smooth_); \
00046   }
00047   macro(VIL1_BYTE, vxl_byte)
00048   macro(VIL1_UINT16, unsigned short)
00049   macro(VIL1_RGB_BYTE, vil1_rgb<unsigned char>)
00050   macro(VIL1_FLOAT, float)
00051 #undef macro
00052   else {
00053     vcl_cerr << "Image must be either UBYTE, SHORT, RGB or FLOAT.\n";
00054     vcl_abort();
00055   }
00056 }
00057 
00058 void osl_canny_smooth_rothwell_adaptive(vil1_image const &image_in,
00059                                         int x0, int y0, int image_size,
00060                                         float const *kernel_, int width_, int k_size_,
00061                                         float * const *dx, float * const *dy, float * const *grad)
00062 {
00063   if (false) { }
00064 #define macro(pt, st) \
00065   else if (vil1_pixel_format(image_in) == pt) { \
00066     vil1_memory_image_of<st > sec(image_in); \
00067     osl_canny_smooth_rothwell_adaptive(const_cast<st const * const *>(sec.row_array()), sec.height(), sec.width(), \
00068                                        x0, y0, image_size, kernel_, width_, k_size_, dx, dy, grad); \
00069   }
00070   macro(VIL1_BYTE, vxl_byte)
00071   macro(VIL1_UINT16, unsigned short)
00072   macro(VIL1_RGB_BYTE, vil1_rgb<unsigned char>)
00073   macro(VIL1_FLOAT, float)
00074 #undef macro
00075   else {
00076     vcl_cerr << "Image must be either UBYTE, SHORT, RGB or FLOAT.\n";
00077     vcl_abort();
00078   }
00079 }
00080 
00081 void osl_canny_smooth(vil1_image const &image_in,
00082                       float const *kernel_, int width_, float const *sub_area_OX_,
00083                       float * const * image_out)
00084 {
00085   if (false) { }
00086 #define macro(pt, st) \
00087   else if (vil1_pixel_format(image_in) == pt) { \
00088     vil1_memory_image_of<st > sec(image_in); \
00089     osl_canny_smooth(const_cast<st const * const *>(sec.row_array()), sec.height(), sec.width(), \
00090                      kernel_, width_, sub_area_OX_, image_out); \
00091   }
00092   macro(VIL1_BYTE, vxl_byte)
00093   macro(VIL1_UINT16, unsigned short)
00094   macro(VIL1_RGB_BYTE, vil1_rgb<unsigned char>)
00095   macro(VIL1_FLOAT, float)
00096 #undef macro
00097   else {
00098     vcl_cerr << "Image must be either UBYTE, SHORT, RGB or FLOAT.\n";
00099     vcl_abort();
00100   }
00101 }