contrib/mul/ipts/ipts_entropy_pyramid.cxx
Go to the documentation of this file.
00001 // This is mul/ipts/ipts_entropy_pyramid.cxx
00002 #include "ipts_entropy_pyramid.h"
00003 //:
00004 // \file
00005 // \brief Compute local entropy at each level of a scale space pyramid
00006 // \author Tim Cootes
00007 
00008 #include "ipts_local_entropy.h"
00009 #include <vimt/vimt_scale_pyramid_builder_2d.h>
00010 #include <vcl_cassert.h>
00011 
00012 //: Compute local entropy at each level of a scale space pyramid
00013 //  Build smooth gaussian pyramid from the image.
00014 //  smooth_pyramid will be of type vxl_byte.  entropy_pyramid is set to be of type float.
00015 //  For each pixel in each image, compute entropy in region (2h+1)x(2h+1)
00016 //  centred on the pixel.
00017 //  Use ipts_scale_space_peaks() to get the position and scale of
00018 //  likely corners
00019 void ipts_entropy_pyramid(const vimt_image_2d_of<vxl_byte>& image,
00020                           vimt_image_pyramid& entropy_pyramid,
00021                           vimt_image_pyramid& smooth_pyramid,
00022                           double scale_step, unsigned half_width)
00023 {
00024   vimt_scale_pyramid_builder_2d<vxl_byte> pyr_builder;
00025   pyr_builder.set_scale_step(scale_step);
00026   pyr_builder.build(smooth_pyramid,image);
00027 
00028   ipts_entropy_pyramid(smooth_pyramid,entropy_pyramid,half_width,0,255);
00029 }
00030 
00031 //: Compute corner strength at each level of a scale space pyramid.
00032 //  smooth_pyramid must be of type vxl_byte.  entropy_pyramid is set to be of type float.
00033 //  For each pixel in each image, compute entropy in region (2h+1)x(2h+1)
00034 //  centred on the pixel.
00035 //  Use ipts_scale_space_peaks() to get the position and scale of likely corners
00036 void ipts_entropy_pyramid(const vimt_image_pyramid& smooth_pyramid,
00037                           vimt_image_pyramid& entropy_pyramid,
00038                           unsigned half_width, int min_v, int max_v)
00039 {
00040   if (smooth_pyramid.n_levels()==0) return;
00041 
00042   assert(smooth_pyramid(0).is_a()=="vimt_image_2d_of<vxl_byte>");
00043 
00044   // Entropy calculation translates results - allow for this
00045   vimt_transform_2d translate;
00046   translate.set_translation(-1.0*half_width,-1.0*half_width);
00047 
00048   // Work out how many levels and be used
00049   int n_levels = 0;
00050   for (int i=0;i<smooth_pyramid.n_levels();++i)
00051   {
00052     const vimt_image_2d_of<vxl_byte>& smooth_im
00053             = static_cast<const vimt_image_2d_of<vxl_byte>&>(smooth_pyramid(i));
00054      if (smooth_im.image().ni()>2*half_width+1 &&
00055          smooth_im.image().nj()>2*half_width+1)  n_levels++;
00056   }
00057 
00058   // Compute entropies for all levels of an image pyramid
00059   entropy_pyramid.resize(n_levels,vimt_image_2d_of<float>());
00060   for (int i=0;i<n_levels;++i)
00061   {
00062     const vimt_image_2d_of<vxl_byte>& smooth_im
00063             = static_cast<const vimt_image_2d_of<vxl_byte>&>(smooth_pyramid(i));
00064     vimt_image_2d_of<float>& entropy_im
00065             = static_cast<vimt_image_2d_of<float>&>(entropy_pyramid(i));
00066     ipts_local_entropy(smooth_im.image(),entropy_im.image(),half_width,min_v,max_v);
00067 
00068     entropy_im.set_world2im(translate*smooth_im.world2im());
00069   }
00070 }