contrib/mul/vil3d/algo/vil3d_binary_dilate.h
Go to the documentation of this file.
00001 #ifndef vil3d_binary_dilate_h_
00002 #define vil3d_binary_dilate_h_
00003 //:
00004 //  \file
00005 //  \brief Perform binary dilation on 3D images
00006 //  \author Tim Cootes
00007 
00008 #include <vil3d/algo/vil3d_structuring_element.h>
00009 #include <vil3d/vil3d_image_view.h>
00010 
00011 
00012 //: Return true if any im[offset[k]] is non-zero
00013 inline bool vil3d_binary_dilate(const bool* im, const vcl_ptrdiff_t* offset, unsigned n)
00014 {
00015   for (unsigned i=0;i<n;++i) if (im[offset[i]]) return true;
00016   return false;
00017 }
00018 
00019 //: Return true if any image pixel under element centred at (i0,j0,k0) is non-zero
00020 //  Checks boundary overlap
00021 inline bool vil3d_binary_dilate(const vil3d_image_view<bool>& image, unsigned plane,
00022                                 const vil3d_structuring_element& element,
00023                                 int i0, int j0, int k0)
00024 {
00025   unsigned n = element.p_i().size();
00026   for (unsigned int a=0;a<n;++a)
00027   {
00028     // Note that -ives become huge positives and are thus ignored by the if
00029     unsigned int i = i0+element.p_i()[a];
00030     unsigned int j = j0+element.p_j()[a];
00031     unsigned int k = k0+element.p_k()[a];
00032     if (i<image.ni() && j<image.nj() && k<image.nk() && image(i,j,k,plane))
00033       return true;
00034   }
00035   return false;
00036 }
00037 
00038 //: Dilates src_image to produce dest_image (assumed single plane)
00039 // \relatesalso vil3d_image_view
00040 // \relatesalso vil3d_structuring_element
00041 void vil3d_binary_dilate(const vil3d_image_view<bool>& src_image,
00042                         vil3d_image_view<bool>& dest_image,
00043                         const vil3d_structuring_element& element);
00044 
00045 
00046 #endif // vil3d_binary_dilate_h_