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