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