utilities.hpp

00001 // This file is part of the imaging2 class library.
00002 //
00003 // University of Innsbruck, Infmath Imaging, 2009.
00004 // http://infmath.uibk.ac.at
00005 //
00006 // All rights reserved.
00007 
00008 
00009 #ifndef IMAGE_UTILITIES_H
00010 #define IMAGE_UTILITIES_H
00011 
00012 #include <image/Image.hpp>
00013 #include <image/Color.hpp>
00014 
00015 namespace imaging
00016 {
00032   template <class float_accessor_t, class vector_accessor_t>
00033   void compute_divergence_field(const float_accessor_t & image, vector_accessor_t & out)
00034   {
00035     const size_t dimension = float_accessor_t::dimension;
00036 
00037     if(image.size() != out.size())
00038       throw Exception("Exception: Dimensions in compute_divergence_field() do not agree.");
00039 
00040     for(size_t i = 0; i < dimension; ++i)
00041     {
00042       ublas::fixed_vector<size_t, dimension> index;
00043       index.assign(0);
00044 
00045       if(image.size()(i) == 0)
00046         break;
00047 
00048       do
00049       {
00050         out[index](i) = 1.0/float_t(dimension) * image[index];
00051       }
00052       while(increment_index(image.size(), i, index));
00053 
00054       ublas::fixed_vector<size_t, dimension> offset;
00055       offset.assign(0);
00056 
00057       for(size_t j = 1; j < image.size()(i); ++j)
00058       {
00059         index(i) = j;
00060         do
00061         {
00062           offset(i) = 1;
00063           out[index](i) = out[index - offset](i) + 1.0/float_t(dimension) * image[index];
00064           offset(i) = 0;
00065         }
00066         while(increment_index(image.size(), i, index));
00067       }
00068     }
00069   }
00070   
00076   template <class image_t>
00077   void blur(image_t & image, float_t width, float_t sigma)
00078   {}
00079   
00080   template <>
00081   void blur(Image<2, float_t> & image, float_t width, float_t sigma);
00082   
00088   template <class image_t>
00089   void edge(image_t & image, float_t radius)
00090   {}
00091   
00092   template <>
00093   void edge(Image<2, float_t> & image, float_t radius);
00094   
00105   template <class image_t>
00106   void absolute_gradient(image_t & image)
00107   {}
00108   
00109   template <>
00110   void absolute_gradient(Image<2, float_t> & image);
00111   
00117   template <class image_t>
00118   typename image_t::data_t max(const image_t & image)
00119   {
00120     if(image.empty()) 
00121       throw Exception("Exception: passed empty image to max(const ImageInterface &).");
00122     
00123     ublas::fixed_vector<size_t, image_t::dimension> index;
00124     index.assign(0);
00125     typename image_t::data_t max_value = image[index];
00126     do
00127     {
00128       typename image_t::data_t temp = image[index];
00129       if(max_value < temp) max_value = temp;
00130     }
00131     while(increment_index(image.size(), index));
00132     
00133     return max_value;
00134   }
00135   
00141   template <class image_t>
00142   typename image_t::data_t min(const image_t & image)
00143   {
00144     if(image.empty()) 
00145       throw Exception("Exception: passed empty image to max(const ImageInterface &).");
00146     
00147     ublas::fixed_vector<size_t, image_t::dimension> index;
00148     index.assign(0);
00149     typename image_t::data_t min_value = image[index];
00150     do
00151     {
00152       typename image_t::data_t temp = image[index];
00153       if(min_value > temp) min_value = temp;
00154     }
00155     while(increment_index(image.size(), index));
00156     
00157     return min_value;
00158   }
00159   
00165   template <class image_t>
00166   bool is_pixel(const image_t & image, const ublas::fixed_vector<size_t, image_t::dimension> & index)
00167   {
00168     for(size_t i = 0; i < image_t::dimension; ++i)
00169       if(index(i) >= image.size()(i))
00170         return false;
00171     
00172     return true;
00173   }
00174   
00175   
00182   void draw_level_set(const Image<2, float_t> & level_set_function, const float_t & level, const Color & color, ColorImage2d & image);
00183   
00189   void image2matrix(const Image<2, float_t> & image, ublas::matrix<float_t> & matrix);
00190 }
00191 
00192 #endif

Generated on Tue Feb 10 10:01:29 2009 for imaging2 by  doxygen 1.5.5