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