contrib/tbl/vepl/vepl_y_gradient.cxx
Go to the documentation of this file.
00001 // This is tbl/vepl/vepl_y_gradient.cxx
00002 #include "vepl_y_gradient.h"
00003 #include <vepl/accessors/vipl_accessors_vil_image_view_base.h>
00004 #include <vipl/vipl_y_gradient.h>
00005 #include <vil/vil_image_view.h>
00006 #include <vil/vil_pixel_format.h>
00007 #include <vil/vil_plane.h>
00008 #include <vil/vil_new.h>
00009 #include <vxl_config.h> // for vxl_byte
00010 
00011 vil_image_resource_sptr vepl_y_gradient(vil_image_resource_sptr image, double scale, double shift)
00012 {
00013   vil_image_resource_sptr img_out = vil_new_image_resource(image->ni(), image->nj(), image->nplanes(), image->pixel_format());
00014 
00015   // multi-planar image
00016   // since vipl does not know the concept of planes, run filter on each plane
00017   if (image->nplanes() > 1) {
00018     if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00019       vil_image_view<vxl_byte> out = image->get_copy_view();
00020       vil_image_view<vxl_byte> in = image->get_view();
00021       vipl_y_gradient<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte>
00022         op(scale, (vxl_byte)(shift+0.5));
00023       for (unsigned int p=0; p<image->nplanes(); ++p) {
00024         vil_image_view<vxl_byte> i = vil_plane(in,p), o = vil_plane(out,p);
00025         op.put_in_data_ptr(&i); op.put_out_data_ptr(&o); op.filter();
00026       }
00027       img_out->put_view(out);
00028     }
00029     else
00030       vcl_cerr << __FILE__ ": vepl_dilate_disk() not implemented for multi-planar " << image << '\n';
00031   }
00032 
00033   // byte greyscale
00034   else if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00035     vil_image_view<vxl_byte> in = image->get_view();
00036     vil_image_view<vxl_byte> out = image->get_copy_view();
00037     vipl_y_gradient<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte>
00038       op(scale, (vxl_byte)(shift+0.5));
00039     op.put_in_data_ptr(&in);
00040     op.put_out_data_ptr(&out);
00041     op.filter();
00042     img_out->put_view(out);
00043   }
00044 
00045   // byte rgb
00046   else if (image->pixel_format() == VIL_PIXEL_FORMAT_RGB_BYTE) {
00047     vil_image_view<vxl_byte> in = image->get_view(); // in will have 3 planes but 1 component
00048     vil_image_view<vxl_byte> out = image->get_copy_view();
00049     vipl_y_gradient<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte>
00050       op(scale, (vxl_byte)(shift+0.5));
00051     op.put_in_data_ptr(&in);
00052     op.put_out_data_ptr(&out);
00053     op.filter();
00054     img_out->put_view(out);
00055   }
00056 
00057   // short
00058   else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00059     vil_image_view<vxl_uint_16> in = image->get_view();
00060     vil_image_view<vxl_uint_16> out = image->get_copy_view();
00061     vipl_y_gradient<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16>
00062       op(scale, (vxl_uint_16)(shift+0.5));
00063     op.put_in_data_ptr(&in);
00064     op.put_out_data_ptr(&out);
00065     op.filter();
00066     img_out->put_view(out);
00067   }
00068 
00069   // int
00070   else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00071     vil_image_view<vxl_uint_32> in = image->get_view();
00072     vil_image_view<vxl_uint_32> out = image->get_copy_view();
00073     vipl_y_gradient<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32>
00074       op(scale, (vxl_uint_32)(shift+0.5));
00075     op.put_in_data_ptr(&in);
00076     op.put_out_data_ptr(&out);
00077     op.filter();
00078     img_out->put_view(out);
00079   }
00080 
00081   // float
00082   else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00083     vil_image_view<float> in = image->get_view();
00084     vil_image_view<float> out = image->get_copy_view();
00085     vipl_y_gradient<vil_image_view_base,vil_image_view_base,float,float>
00086       op(scale, (float)shift);
00087     op.put_in_data_ptr(&in);
00088     op.put_out_data_ptr(&out);
00089     op.filter();
00090     img_out->put_view(out);
00091   }
00092 
00093   // double
00094   else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00095     vil_image_view<double> in = image->get_view();
00096     vil_image_view<double> out = image->get_copy_view();
00097     vipl_y_gradient<vil_image_view_base,vil_image_view_base,double,double>
00098       op(scale, shift);
00099     op.put_in_data_ptr(&in);
00100     op.put_out_data_ptr(&out);
00101     op.filter();
00102     img_out->put_view(out);
00103   }
00104 
00105   //
00106   else
00107     vcl_cerr << __FILE__ ": vepl_y_gradient() not implemented for " << image << '\n';
00108 
00109   return img_out;
00110 }
00111