contrib/mul/ipts/ipts_orientation_pyramid.cxx
Go to the documentation of this file.
00001 // This is mul/ipts/ipts_orientation_pyramid.cxx
00002 #include "ipts_orientation_pyramid.h"
00003 //:
00004 // \file
00005 // \brief Compute edge orientations at each level of a scale space pyramid
00006 // \author Tim Cootes
00007 
00008 #include <vil/algo/vil_orientations.h>
00009 #include <vimt/vimt_image_2d_of.h>
00010 #include <vcl_cassert.h>
00011 
00012 //: Compute edge orientations at each level of a scale space pyramid.
00013 //  smooth_pyramid must be of type float. orient_pyramid is set to be of type vxl_byte.
00014 //  Uses vil_orientations_at_edges() on each level of the pyramid.
00015 void ipts_orientation_pyramid(const vimt_image_pyramid& smooth_pyramid,
00016                               vimt_image_pyramid& orient_pyramid,
00017                               float grad_threshold,
00018                               unsigned n_orientations)
00019 {
00020   if (smooth_pyramid.n_levels()==0) return;
00021 
00022   assert(smooth_pyramid(0).is_a()=="vimt_image_2d_of<float>");
00023 
00024   int n_levels = smooth_pyramid.n_levels();
00025 
00026   // Compute entropies for all levels of an image pyramid
00027   orient_pyramid.resize(n_levels,vimt_image_2d_of<vxl_byte>());
00028   for (int i=0;i<n_levels;++i)
00029   {
00030     const vimt_image_2d_of<float>& smooth_im
00031             = static_cast<const vimt_image_2d_of<float>&>(smooth_pyramid(i));
00032     vimt_image_2d_of<vxl_byte>& orient_im
00033             = static_cast<vimt_image_2d_of<vxl_byte>&>(orient_pyramid(i));
00034 
00035     vil_image_view<float> grad_i,grad_j,grad_mag;
00036     vil_sobel_3x3(smooth_im.image(),grad_i,grad_j);
00037     vil_orientations_at_edges(grad_i,grad_j,orient_im.image(),grad_mag,
00038                               grad_threshold,n_orientations);
00039 
00040     orient_im.set_world2im(smooth_im.world2im());
00041   }
00042 }