contrib/tbl/vepl/vepl_moment.cxx
Go to the documentation of this file.
00001 // This is tbl/vepl/vepl_moment.cxx
00002 #include "vepl_moment.h"
00003 #include <vcl_iostream.h>
00004 #include <vepl/accessors/vipl_accessors_vil_image_view_base.h>
00005 #include <vipl/vipl_moment.h>
00006 #include <vil/vil_image_view.h>
00007 #include <vil/vil_pixel_format.h>
00008 #include <vil/vil_new.h>
00009 #include <vxl_config.h> // for vxl_byte
00010 
00011 vil_image_resource_sptr vepl_moment(vil_image_resource_sptr image, int order, int width, int height)
00012 {
00013   vil_image_resource_sptr img_out = vil_new_image_resource(image->ni(), image->nj(), image->nplanes(), image->pixel_format());
00014 
00015   // byte rgb
00016   if (image->nplanes() > 1 || image->pixel_format() == VIL_PIXEL_FORMAT_RGB_BYTE) {
00017     vcl_cerr << __FILE__ ": vepl_moment() cannot be implemented for colour images\n";
00018   }
00019 
00020   // byte greyscale
00021   else if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00022     vil_image_view<vxl_byte> in = image->get_view();
00023     vil_image_view<vxl_byte> out = image->get_copy_view();
00024     vipl_moment<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte> op(order, width, height);
00025     op.put_in_data_ptr(&in);
00026     op.put_out_data_ptr(&out);
00027     op.filter();
00028     img_out->put_view(out);
00029   }
00030 
00031   // short
00032   else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00033     vil_image_view<vxl_uint_16> in = image->get_view();
00034     vil_image_view<vxl_uint_16> out = image->get_copy_view();
00035     vipl_moment<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16> op(order, width, height);
00036     op.put_in_data_ptr(&in);
00037     op.put_out_data_ptr(&out);
00038     op.filter();
00039     img_out->put_view(out);
00040   }
00041 
00042   // int
00043   else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00044     vil_image_view<vxl_uint_32> in = image->get_view();
00045     vil_image_view<vxl_uint_32> out = image->get_copy_view();
00046     vipl_moment<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32> op(order, width, height);
00047     op.put_in_data_ptr(&in);
00048     op.put_out_data_ptr(&out);
00049     op.filter();
00050     img_out->put_view(out);
00051   }
00052 
00053   // float
00054   else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00055     vil_image_view<float> in = image->get_view();
00056     vil_image_view<float> out = image->get_copy_view();
00057     vipl_moment<vil_image_view_base,vil_image_view_base,float,float> op(order, width, height);
00058     op.put_in_data_ptr(&in);
00059     op.put_out_data_ptr(&out);
00060     op.filter();
00061     img_out->put_view(out);
00062   }
00063 
00064   // double
00065   else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00066     vil_image_view<double> in = image->get_view();
00067     vil_image_view<double> out = image->get_copy_view();
00068     vipl_moment<vil_image_view_base,vil_image_view_base,double,double> op(order, width, height);
00069     op.put_in_data_ptr(&in);
00070     op.put_out_data_ptr(&out);
00071     op.filter();
00072     img_out->put_view(out);
00073   }
00074 
00075   //
00076   else
00077     vcl_cerr << __FILE__ ": vepl_moment() not implemented for " << image << '\n';
00078 
00079   return img_out;
00080 }
00081