contrib/mul/vimt/vimt_load.h
Go to the documentation of this file.
00001 // This is mul/vimt/vimt_load.h
00002 #ifndef vimt_load_h_
00003 #define vimt_load_h_
00004 //:
00005 // \file
00006 // \author Martin Roberts, Ian Scott
00007 
00008 #include <vil/vil_image_resource.h>
00009 #include <vil/vil_convert.h>
00010 #include <vil/vil_load.h>
00011 #include <vimt/vimt_image_2d_of.h>
00012 
00013 //: Create a transform from the properties of image resource.
00014 // \param unit_scaling is to convert from metres to desired world units (e.g. 1000 for mm)
00015 vimt_transform_2d vimt_load_transform(const vil_image_resource_sptr &im,
00016                                       float unit_scaling=1.0f);
00017 
00018 //: Create a transform from the properties of image resource, assuming a right-hand world frame.
00019 // \param unit_scaling is to convert from metres to desired world units (e.g. 1000 for mm)
00020 // \note This version incorporates a reflection through the x-axis so that
00021 // the transform is put into a right-handed coordinate frame
00022 // (with y increasing from bottom to top of image).
00023 vimt_transform_2d vimt_load_transform_right_hand(const vil_image_resource_sptr &im,
00024                                                  float unit_scaling=1.0f);
00025 
00026 
00027 //: Load image from path into given image (forcing to given pixel type)
00028 // \param unit_scaling is to convert from metres to desired world units (e.g. 1000 for mm)
00029 template<class T> inline
00030 void vimt_load(const vcl_string& path,
00031                vimt_image_2d_of<T>& image,
00032                float unit_scaling=1.0f)
00033 {
00034   vil_image_resource_sptr ir = vil_load_image_resource(path.c_str());
00035   if (ir.ptr()==0)
00036   {
00037     image.image().set_size(0,0);
00038     return;
00039   }
00040   image.image() = vil_convert_cast(T(),ir->get_view(0,ir->ni(),0,ir->nj()));
00041   image.set_world2im(vimt_load_transform(ir, unit_scaling));
00042 }
00043 
00044 
00045 //: Load image from path into given image (forcing to given pixel type)
00046 // \param unit_scaling is to convert from metres to desired world units (e.g. 1000 for mm)
00047 // \note This version incorporates a reflection through the x-axis so that
00048 // the transform is put into a right-handed coordinate frame
00049 // (with y increasing from bottom to top of image).
00050 template<class T> inline
00051 void vimt_load_right_hand(const vcl_string& path,
00052                           vimt_image_2d_of<T>& image,
00053                           float unit_scaling=1.0f)
00054 {
00055   vil_image_resource_sptr ir = vil_load_image_resource(path.c_str());
00056   if (ir.ptr()==0)
00057   {
00058     image.image().set_size(0,0);
00059     return;
00060   }
00061 
00062   image.image() = vil_convert_cast(T(),
00063     ir->get_view(0,ir->ni(),0,ir->nj()));
00064 
00065   image.set_world2im(vimt_load_transform_right_hand(ir, unit_scaling));
00066 }
00067 
00068 
00069 #endif // vimt_load_h_