contrib/tbl/vepl1/vepl1_gaussian_convolution.cxx
Go to the documentation of this file.
00001 // This is tbl/vepl1/vepl1_gaussian_convolution.cxx
00002 #include "vepl1_gaussian_convolution.h"
00003 #include <vcl_iostream.h>
00004 #include <vipl/accessors/vipl_accessors_vil1_image.h>
00005 #include <vipl/vipl_gaussian_convolution.h>
00006 #include <vil1/vil1_memory_image_of.h>
00007 #include <vil1/vil1_rgb.h>
00008 #include <vxl_config.h> // for vxl_byte
00009 
00010 vil1_image vepl1_gaussian_convolution(vil1_image const& image, double sigma, double cutoff)
00011 {
00012   // byte greyscale
00013   if (vil1_pixel_format(image) == VIL1_BYTE) {
00014     vil1_memory_image_of<vxl_byte> mem(image); // load in memory to pass to filter
00015     vil1_memory_image_of<vxl_byte> out(image);
00016     vipl_gaussian_convolution<vil1_image,vil1_image,vxl_byte,vxl_byte> op(sigma, cutoff);
00017     op.put_in_data_ptr(&mem);
00018     op.put_out_data_ptr(&out);
00019     op.filter();
00020     return out;
00021   }
00022 
00023   // byte rgb: process colour bands independently as ubyte images
00024   else if (vil1_pixel_format(image) == VIL1_RGB_BYTE)
00025   {
00026 #define r_g_b vil1_rgb<vxl_byte> // cannot use typedef since that may cause ambiguous overload problems
00027     vil1_memory_image_of<r_g_b > in(image); // load in memory to pass to filter
00028     vil1_memory_image_of<r_g_b > out(image);
00029     vil1_memory_image_of<vxl_byte> mem((vxl_byte*)(in.get_buffer()),3*in.width(),in.height()); // reinterpret as vxl_byte
00030     vil1_memory_image_of<vxl_byte> mout((vxl_byte*)(out.get_buffer()),3*in.width(),in.height());
00031     vipl_gaussian_convolution<vil1_image,vil1_image,vxl_byte,vxl_byte> op(sigma, cutoff);
00032     op.put_in_data_ptr(&mem);
00033     op.put_out_data_ptr(&mout);
00034     op.filter();
00035     return out;
00036   }
00037 
00038 
00039   // 16-bit greyscale
00040   else if (vil1_pixel_format(image) == VIL1_UINT16) {
00041     vil1_memory_image_of<vxl_uint_16> mem(image); // load in memory to pass to filter
00042     vil1_memory_image_of<vxl_uint_16> out(image);
00043     vipl_gaussian_convolution<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(sigma, cutoff);
00044     op.put_in_data_ptr(&mem);
00045     op.put_out_data_ptr(&out);
00046     op.filter();
00047     return out;
00048   }
00049 
00050   // float
00051   else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00052     vil1_memory_image_of<float> mem(image); // load in memory to pass to filter
00053     vil1_memory_image_of<float> out(image);
00054     vipl_gaussian_convolution<vil1_image,vil1_image,float,float> op(sigma, cutoff);
00055     op.put_in_data_ptr(&mem);
00056     op.put_out_data_ptr(&out);
00057     op.filter();
00058     return out;
00059   }
00060 
00061   // double
00062   else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00063     vil1_memory_image_of<double> mem(image); // load in memory to pass to filter
00064     vil1_memory_image_of<double> out(image);
00065     vipl_gaussian_convolution<vil1_image,vil1_image,double,double> op(sigma, cutoff);
00066     op.put_in_data_ptr(&mem);
00067     op.put_out_data_ptr(&out);
00068     op.filter();
00069     return out;
00070   }
00071 
00072   //
00073   else {
00074     vcl_cerr << __FILE__ ": vepl1_gaussian_convolution() not implemented for " << image << vcl_endl;
00075     return 0;
00076   }
00077 }
00078