00001
00002
00003
00004
00005
00006 #include "vil3d_binary_dilate.h"
00007 #include <vcl_cassert.h>
00008
00009
00010 void vil3d_binary_dilate(const vil3d_image_view<bool>& src_image,
00011 vil3d_image_view<bool>& dest_image,
00012 const vil3d_structuring_element& element)
00013 {
00014 assert(src_image.nplanes()==1);
00015 unsigned ni = src_image.ni();
00016 unsigned nj = src_image.nj();
00017 unsigned nk = src_image.nk();
00018 dest_image.set_size(ni,nj,nk,1);
00019
00020 vcl_ptrdiff_t s_istep = src_image.istep(), s_jstep = src_image.jstep();
00021 vcl_ptrdiff_t s_kstep = src_image.kstep();
00022 vcl_ptrdiff_t d_istep = dest_image.istep();
00023
00024 vcl_vector<vcl_ptrdiff_t> offset;
00025 vil3d_compute_offsets(offset,element,s_istep,s_jstep,s_kstep);
00026
00027
00028 int ilo = -element.min_i();
00029 int ihi = ni-1-element.max_i();
00030 int jlo = -element.min_j();
00031 int jhi = nj-1-element.max_j();
00032 int klo = -element.min_k();
00033 int khi = nk-1-element.max_k();
00034
00035
00036 for (int i=0;i<ilo;++i)
00037 for (unsigned int j=0;j<nj;++j)
00038 for (unsigned int k=0;k<nk;++k)
00039 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00040
00041 for (unsigned int i=ihi+1;i<ni;++i)
00042 for (unsigned int j=0;j<nj;++j)
00043 for (unsigned int k=0;k<nk;++k)
00044 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00045
00046 for (int i=ilo;i<=ihi;++i)
00047 for (int j=0;j<jlo;++j)
00048 for (unsigned int k=0;k<nk;++k)
00049 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00050
00051 for (int i=ilo;i<=ihi;++i)
00052 for (unsigned int j=jhi+1;j<nj;++j)
00053 for (unsigned int k=0;k<nk;++k)
00054 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00055
00056 for (int k=0;k<klo;++k)
00057 for (int i=ilo;i<=ihi;++i)
00058 for (int j=jlo;j<=jhi;++j)
00059 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00060
00061 for (unsigned int k=khi+1;k<nk;++k)
00062 for (int i=ilo;i<=ihi;++i)
00063 for (int j=jlo;j<=jhi;++j)
00064 dest_image(i,j,k,0)=vil3d_binary_dilate(src_image,0,element,i,j,k);
00065
00066 for (int k=klo;k<=khi;++k)
00067 for (int j=jlo;j<=jhi;++j)
00068 {
00069 const bool* src_p = &src_image(ilo,j,k);
00070 bool* dest_p = &dest_image(ilo,j,k);
00071
00072 for (int i=ilo;i<=ihi;++i,src_p+=s_istep,dest_p+=d_istep)
00073 *dest_p=vil3d_binary_dilate(src_p,&offset[0],offset.size());
00074 }
00075 }