contrib/mul/vil3d/algo/vil3d_grad_3x3x3.h
Go to the documentation of this file.
00001 // This is mul/vil3d/algo/vil3d_grad_3x3x3.h
00002 #ifndef vil3d_grad_3x3x3_h_
00003 #define vil3d_grad_3x3x3_h_
00004 //:
00005 // \file
00006 // \brief Compute gradient using 3D version of sobel operator.
00007 // \author Tim Cootes
00008 
00009 #include <vil3d/algo/vil3d_grad_1x3.h>
00010 #include <vil3d/algo/vil3d_smooth_121.h>
00011 
00012 //: Compute i-gradient using 3D version of sobel operator.
00013 //  Resulting image has same size. Border pixels set to zero.
00014 //  Smooths in j and k with 1-2-1 filters, then applies (-0.5 0 0.5)
00015 //  filter along i.  Intermediate images of type destT
00016 template<class srcT, class destT>
00017 void vil3d_grad_3x3x3_i(const vil3d_image_view<srcT>& src_im,
00018                         vil3d_image_view<destT>& grad_im)
00019 {
00020   vil3d_image_view<destT> tmp_im;
00021   vil3d_smooth_121_j(src_im,grad_im);  // Use grad_im as temporary storage
00022   vil3d_smooth_121_k(grad_im,tmp_im);
00023   vil3d_grad_1x3_i(tmp_im,grad_im);
00024 }
00025 
00026 //: Compute j-gradient using 3D version of sobel operator.
00027 //  Resulting image has same size. Border pixels set to zero.
00028 //  Smooths in i and k with 1-2-1 filters, then applies (-0.5 0 0.5)
00029 //  filter along j.  Intermediate images of type destT
00030 template<class srcT, class destT>
00031 void vil3d_grad_3x3x3_j(const vil3d_image_view<srcT>& src_im,
00032                         vil3d_image_view<destT>& grad_im)
00033 {
00034   vil3d_image_view<destT> tmp_im;
00035   vil3d_smooth_121_i(src_im,grad_im);  // Use grad_im as temporary storage
00036   vil3d_smooth_121_k(grad_im,tmp_im);
00037   vil3d_grad_1x3_j(tmp_im,grad_im);
00038 }
00039 
00040 
00041 //: Compute k-gradient using 3D version of sobel operator.
00042 //  Resulting image has same size. Border pixels set to zero.
00043 //  Smooths in i and j with 1-2-1 filters, then applies (-0.5 0 0.5)
00044 //  filter along k.  Intermediate images of type destT
00045 template<class srcT, class destT>
00046 void vil3d_grad_3x3x3_k(const vil3d_image_view<srcT>& src_im,
00047                         vil3d_image_view<destT>& grad_im)
00048 {
00049   vil3d_image_view<destT> tmp_im;
00050   vil3d_smooth_121_i(src_im,grad_im);  // Use grad_im as temporary storage
00051   vil3d_smooth_121_j(grad_im,tmp_im);
00052   vil3d_grad_1x3_k(tmp_im,grad_im);
00053 }
00054 
00055 //: Compute gradients using 3D version of sobel operator.
00056 //  Resulting images have same size as src_im. Border pixels set to zero.
00057 //  Smooths in two directions with 1-2-1 filters, then applies (-0.5 0 0.5)
00058 //  filter along the third.  Intermediate images of type destT
00059 template<class srcT, class destT>
00060 void vil3d_grad_3x3x3(const vil3d_image_view<srcT>& src_im,
00061                         vil3d_image_view<destT>& grad_i,
00062                         vil3d_image_view<destT>& grad_j,
00063                         vil3d_image_view<destT>& grad_k)
00064 {
00065   vil3d_image_view<destT> smth_i,smth_ij,smth_ik;
00066   vil3d_smooth_121_i(src_im,smth_i);
00067   vil3d_smooth_121_j(smth_i,smth_ij);
00068   vil3d_smooth_121_k(smth_i,smth_ik);
00069   vil3d_grad_1x3_j(smth_ik,grad_j);
00070   vil3d_grad_1x3_k(smth_ij,grad_k);
00071 
00072   vil3d_image_view<destT> smth_j,smth_jk;
00073   vil3d_smooth_121_j(src_im,smth_j);
00074   vil3d_smooth_121_k(smth_j,smth_jk);
00075   vil3d_grad_1x3_i(smth_jk,grad_i);
00076 }
00077 
00078 #endif