contrib/mul/vil3d/algo/vil3d_fill_border.h
Go to the documentation of this file.
00001 // This is contrib/mul/vil3d/algo/vil3d_fill_border.h
00002 #ifndef vil3d_fill_border_h_
00003 #define vil3d_fill_border_h_
00004 //:
00005 // \file
00006 // \brief Fills border pixels of image with given value
00007 // \author Tim Cootes
00008 
00009 #include <vil3d/vil3d_crop.h>
00010 
00011 //: Fills border pixels of image with given value
00012 template<class T>
00013 inline void vil3d_fill_border(vil3d_image_view<T>& im, unsigned bi, unsigned bj, unsigned bk, T value)
00014 {
00015   unsigned ni=im.ni();
00016   if (ni<=2*bi) { im.fill(value); return; }
00017   unsigned nj=im.nj();
00018   if (nj<=2*bj) { im.fill(value); return; }
00019   unsigned nk=im.nk();
00020   if (nk<=2*bk) { im.fill(value); return; }
00021 
00022   // Fill borders by filling elements of cropped images
00023   if (bi>0)
00024   {
00025     vil3d_image_view<T> im_ilo=vil3d_crop(im,0,bi, 0,nj, 0,nk);
00026     im_ilo.fill(value);
00027     vil3d_image_view<T> im_ihi=vil3d_crop(im,ni-bi,bi, 0,nj, 0,nk);
00028     im_ihi.fill(value);
00029   }
00030 
00031   if (bj>0)
00032   {
00033     vil3d_image_view<T> im_jlo=vil3d_crop(im,0,ni, 0,bj, 0,nk);
00034     im_jlo.fill(value);
00035     vil3d_image_view<T> im_jhi=vil3d_crop(im,0,ni, bj-bj,bj, 0,nk);
00036     im_jhi.fill(value);
00037   }
00038 
00039   if (bk>0)
00040   {
00041     vil3d_image_view<T> im_klo=vil3d_crop(im,0,ni, 0,nj, 0,bk);
00042     im_klo.fill(value);
00043     vil3d_image_view<T> im_khi=vil3d_crop(im,0,ni, 0,nj, nk-bk,bk);
00044     im_khi.fill(value);
00045   }
00046 }
00047 
00048 #endif // vil3d_fill_border_h_