contrib/tbl/vepl1/vepl1_moment.cxx
Go to the documentation of this file.
00001 // This is tbl/vepl1/vepl1_moment.cxx
00002 #include "vepl1_moment.h"
00003 #include <vcl_iostream.h>
00004 #include <vipl/accessors/vipl_accessors_vil1_image.h>
00005 #include <vipl/vipl_moment.h>
00006 #include <vil1/vil1_memory_image_of.h>
00007 #include <vxl_config.h> // for vxl_byte
00008 
00009 vil1_image vepl1_moment(vil1_image const& image, int order, int width, int height)
00010 {
00011   // byte greyscale
00012   if (vil1_pixel_format(image) == VIL1_BYTE) {
00013     vil1_memory_image_of<vxl_byte> mem(image); // load in memory to pass to filter
00014     vil1_memory_image_of<vxl_byte> out(image);
00015     vipl_moment<vil1_image,vil1_image,vxl_byte,vxl_byte> op(order, width, height);
00016     op.put_in_data_ptr(&mem);
00017     op.put_out_data_ptr(&out);
00018     op.filter();
00019     return out;
00020   }
00021 
00022   // byte rgb
00023   else if (vil1_pixel_format(image) == VIL1_RGB_BYTE) {
00024     vcl_cerr << __FILE__ ": vepl1_moment() cannot be implemented for colour images\n";
00025     return 0;
00026   }
00027 
00028   // 16-bit greyscale
00029   else if (vil1_pixel_format(image) == VIL1_UINT16) {
00030     vil1_memory_image_of<vxl_uint_16> mem(image); // load in memory to pass to filter
00031     vil1_memory_image_of<vxl_uint_16> out(image);
00032     vipl_moment<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(order, width, height);
00033     op.put_in_data_ptr(&mem);
00034     op.put_out_data_ptr(&out);
00035     op.filter();
00036     return out;
00037   }
00038 
00039   // float
00040   else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00041     vil1_memory_image_of<float> mem(image); // load in memory to pass to filter
00042     vil1_memory_image_of<float> out(image);
00043     vipl_moment<vil1_image,vil1_image,float,float> op(order, width, height);
00044     op.put_in_data_ptr(&mem);
00045     op.put_out_data_ptr(&out);
00046     op.filter();
00047     return out;
00048   }
00049 
00050   // double
00051   else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00052     vil1_memory_image_of<double> mem(image); // load in memory to pass to filter
00053     vil1_memory_image_of<double> out(image);
00054     vipl_moment<vil1_image,vil1_image,double,double> op(order, width, height);
00055     op.put_in_data_ptr(&mem);
00056     op.put_out_data_ptr(&out);
00057     op.filter();
00058     return out;
00059   }
00060 
00061   //
00062   else {
00063     vcl_cerr << __FILE__ ": vepl1_moment() not implemented for " << image << vcl_endl;
00064     return 0;
00065   }
00066 }
00067