contrib/mul/vil3d/algo/vil3d_exp_distance_transform.h
Go to the documentation of this file.
00001 #ifndef vil3d_exp_distance_transform_h_
00002 #define vil3d_exp_distance_transform_h_
00003 //:
00004 //  \file
00005 //  \brief Apply non-linear filter to a 3D image.
00006 //  \author Tim Cootes
00007 
00008 #include <vil3d/vil3d_image_view.h>
00009 #include <vil3d/vil3d_plane.h>
00010 #include <vil3d/algo/vil3d_make_edt_filter.h>
00011 #include <vil3d/algo/vil3d_max_product_filter.h>
00012 
00013 //: Apply nonlinear filter to 3D image
00014 //  Place an exponential decay kernel, with width to half maxima
00015 //  of (width_i,width_j,width_k) in each dimension, at every voxel.
00016 //  Replace each voxel with the maximum of all such kernels passing
00017 //  through.  This is closely related to applying a distance transform
00018 //  to the log of the image.
00019 template<class T>
00020 void vil3d_exp_distance_transform(vil3d_image_view<T>& image,
00021                            double width_i,
00022                            double width_j,
00023                            double width_k,
00024                            int r)
00025 {
00026   // Construct filter
00027   vil3d_structuring_element se;
00028   vcl_vector<double> f;
00029   vil3d_make_edt_filter(width_i,width_j,width_k,r,se,f);
00030 
00031   for (unsigned p=0;p<image.nplanes();++p)
00032   {
00033     vil3d_image_view<T> image_p = vil3d_plane(image,p);
00034 
00035     // Forward pass
00036     vil3d_max_product_filter(image_p,se,f);
00037     unsigned ni = image.ni();
00038     unsigned nj = image.nj();
00039     unsigned nk = image.nk();
00040 
00041     vcl_ptrdiff_t istep = image.istep();
00042     vcl_ptrdiff_t jstep = image.jstep();
00043     vcl_ptrdiff_t kstep = image.kstep();
00044 
00045     vil3d_image_view<T> flipped_image(&image(ni-1,nj-1,nk-1,p),
00046                                  ni,nj,nk,1,
00047                                  -istep,-jstep,-kstep,
00048                                  image.planestep());
00049     // Backward pass
00050     vil3d_max_product_filter(flipped_image,se,f);
00051   }
00052 }
00053 
00054 
00055 #endif // vil3d_exp_distance_transform_h_