Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CoreFunctions.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLCore/src/ICLCore/CoreFunctions.h                    **
00010 ** Module : ICLCore                                                **
00011 ** Authors: Christof Elbrechter, Michael Goetting, Robert          **
00012 **          Haschke, Andre Justus, Sergius Gaulik                  **
00013 **                                                                 **
00014 **                                                                 **
00015 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00016 ** This file may be used under the terms of the GNU Lesser General **
00017 ** Public License version 3.0 as published by the                  **
00018 **                                                                 **
00019 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00020 ** included in the packaging of this file.  Please review the      **
00021 ** following information to ensure the license requirements will   **
00022 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00023 **                                                                 **
00024 ** The development of this software was supported by the           **
00025 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00026 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00027 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00028 ** Excellence Initiative.                                          **
00029 **                                                                 **
00030 ********************************************************************/
00031 
00032 #pragma once
00033 
00034 #include <ICLUtils/Macros.h>
00035 #include <ICLUtils/Point32f.h>
00036 #include <ICLUtils/ClippedCast.h>
00037 #include <ICLUtils/PThreadFix.h>
00038 #include <ICLUtils/SSEUtils.h>
00039 
00040 #include <ICLCore/Types.h>
00041 #include <ICLCore/ImgParams.h>
00042 
00043 #include <string>
00044 #include <cstring>
00045 #include <iostream>
00046 #include <vector>
00047 
00049 
00052 namespace icl {
00053   namespace core{
00054    
00055   /* {{{ Global functions */
00056   
00058 
00098     ICLCore_API ImgBase *imgNew(depth d = depth8u, const ImgParams &params = ImgParams::null);
00099     
00101     inline ImgBase *imgNew(depth d, const utils::Size& size, format fmt, 
00102                            const utils::Rect &roi=utils::Rect::null){
00103       return imgNew(d,ImgParams(size,fmt,roi));
00104     }
00105   
00107     inline ImgBase *imgNew(depth d, const utils::Size& size, int channels=1, 
00108                            const utils::Rect &roi=utils::Rect::null){
00109       return imgNew(d,ImgParams(size,channels,roi));
00110     }
00111    
00113     inline ImgBase *imgNew(depth d, const utils::Size& size, int channels, format fmt, 
00114                            const utils::Rect &roi=utils::Rect::null){
00115       return imgNew(d,ImgParams(size,channels,fmt,roi));
00116     }
00117   
00118     
00120 
00137     ICLCore_API ImgBase *ensureDepth(ImgBase **ppoImage, depth eDepth);
00138   
00140     ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, depth d, const ImgParams &params);
00141   
00143 
00155     inline ImgBase *ensureCompatible(ImgBase **dst, depth d,const utils::Size& size,int channels, const utils::Rect &roi=utils::Rect::null)
00156        { return ensureCompatible(dst,d,ImgParams(size,channels,roi)); }
00157   
00159     inline ImgBase *ensureCompatible(ImgBase **dst, depth d,const utils::Size& size, format fmt, const utils::Rect &roi=utils::Rect::null)
00160        { return ensureCompatible(dst,d,ImgParams(size,fmt,roi)); }
00161     
00163 
00166     ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, depth d, const utils::Size &size, int channels, format fmt, const utils::Rect &roi = utils::Rect::null);
00167     
00169 
00179     ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, const ImgBase *src);
00180   
00182 
00185     ICLCore_API int getChannelsOfFormat(format fmt);
00186   
00188     template<class T> inline depth getDepth();
00189   
00190   
00192     ICLCore_API std::ostream &operator<<(std::ostream &s, const format &f);
00193     
00195     ICLCore_API std::ostream &operator<<(std::ostream &s, const depth &d);
00196   
00198     ICLCore_API std::istream &operator>>(std::istream &s, format &f);
00199     
00201     ICLCore_API std::istream &operator>>(std::istream &s, depth &d);
00202   
00203     
00205   #define ICL_INSTANTIATE_DEPTH(T)                                        \
00206     template<> inline depth getDepth<icl ## T>() { return depth ## T; }
00207   ICL_INSTANTIATE_ALL_DEPTHS  
00208   #undef ICL_INSTANTIATE_DEPTH
00209 
00211 
00212     ICLCore_API unsigned int getSizeOf(depth eDepth);
00213   
00215     template <class T>
00216     inline void copy(const T *src, const T *srcEnd, T *dst){
00217       //std::copy<T>(src,srcEnd,dst);
00218       memcpy(dst,src,(srcEnd-src)*sizeof(T));
00219     } 
00220   
00221   
00222   #ifdef ICL_HAVE_IPP
00223 
00224     template <>
00225     inline void copy<icl8u>(const icl8u *poSrcStart, const icl8u *poSrcEnd, icl8u *poDst){
00226       ippsCopy_8u(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00227     }
00228     template <>
00229     inline void copy<icl16s>(const icl16s *poSrcStart, const icl16s *poSrcEnd, icl16s *poDst){
00230       ippsCopy_16s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00231     }
00232     template <>
00233     inline void copy<icl32s>(const icl32s *poSrcStart, const icl32s *poSrcEnd, icl32s *poDst){
00234       ippsCopy_32s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00235     }
00236     template <>
00237     inline void copy<icl32f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32f *poDst){
00238       ippsCopy_32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00239     }
00240     template <>
00241     inline void copy<icl64f>(const icl64f *poSrcStart, const icl64f *poSrcEnd, icl64f *poDst){
00242       ippsCopy_64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00243     }
00245   #endif
00246   
00247   
00248   
00249   
00251     template <class srcT,class dstT>
00252     inline void convert(const srcT *poSrcStart,const srcT *poSrcEnd, dstT *poDst){
00253       std::transform(poSrcStart,poSrcEnd,poDst,utils::clipped_cast<srcT,dstT>);
00254     }
00255     
00256   #ifdef ICL_HAVE_IPP 
00257 
00258 
00259     template<> inline void convert<icl8u,icl32f>(const icl8u *poSrcStart,const icl8u *poSrcEnd, icl32f *poDst){
00260       ippsConvert_8u32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00261     }
00263     template<> inline void convert<icl16s,icl32s>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32s *poDst){
00264       ippsConvert_16s32s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00265     }
00266     template<> inline void convert<icl16s,icl32f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32f *poDst){
00267       ippsConvert_16s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00268     }
00269     template<> inline void convert<icl16s,icl64f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl64f *poDst){
00270       ippsConvert_16s64f_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),0);
00271     }
00272     
00273     // from icl32s functions
00274     template<> inline void convert<icl32s,icl16s>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl16s *poDst){
00275       ippsConvert_32s16s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00276     }
00277     template<> inline void convert<icl32s,icl32f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl32f *poDst){
00278       ippsConvert_32s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00279     }
00280     template<> inline void convert<icl32s,icl64f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl64f *poDst){
00281       ippsConvert_32s64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00282     }
00283   
00284     // from icl32f functions
00285     template <> inline void convert<icl32f,icl8u>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl8u *poDst){
00286       ippsConvert_32f8u_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
00287     } 
00288     template <> inline void convert<icl32f,icl16s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl16s *poDst){
00289       ippsConvert_32f16s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
00290     } 
00291     template <> inline void convert<icl32f,icl32s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32s *poDst){
00292       ippsConvert_32f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
00293     } 
00294     template <> inline void convert<icl32f,icl64f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl64f *poDst){
00295       ippsConvert_32f64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00296     } 
00297   
00298     // from icl64f functions 
00299     template<> inline void convert<icl64f,icl32f>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32f *poDst){
00300       ippsConvert_64f32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
00301     }
00302     template <> inline void convert<icl64f,icl32s>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32s *poDst){
00303       ippsConvert_64f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
00304     }
00306   #elif defined ICL_HAVE_SSE2
00307 
00309 
00310     template<> ICLCore_API void convert<icl8u,icl32f>(const icl8u *poSrcStart,const icl8u *poSrcEnd, icl32f *poDst);
00311 
00313     template<> ICLCore_API void convert<icl16s,icl32s>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32s *poDst);
00314     template<> ICLCore_API void convert<icl16s,icl32f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32f *poDst);
00315     template<> ICLCore_API void convert<icl16s,icl64f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl64f *poDst);
00316     
00317     // from icl32s functions
00318     template<> ICLCore_API void convert<icl32s,icl16s>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl16s *poDst);
00319     template<> ICLCore_API void convert<icl32s,icl32f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl32f *poDst);
00320     template<> ICLCore_API void convert<icl32s,icl64f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl64f *poDst);
00321   
00322     // from icl32f functions
00323     template <> ICLCore_API void convert<icl32f,icl8u>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl8u *poDst);
00324     template <> ICLCore_API void convert<icl32f,icl16s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl16s *poDst);
00325     template <> ICLCore_API void convert<icl32f,icl32s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32s *poDst);
00326     template <> ICLCore_API void convert<icl32f,icl64f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl64f *poDst);
00327   
00328     // from icl64f functions 
00329     template<> ICLCore_API void convert<icl64f,icl32f>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32f *poDst);
00330     template <> ICLCore_API void convert<icl64f,icl32s>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32s *poDst);
00331 
00333   #endif 
00334   
00335    
00337 
00343     template<class T>
00344     ICLCore_API inline void getMinAndMax(T a, T b, T c, T &minVal, T &maxVal){
00345       if(a<b) {
00346         minVal=a;
00347         maxVal=b;
00348       }
00349       else {
00350         minVal=b;
00351         maxVal=a;       
00352       }
00353       if(c<minVal)
00354         minVal=c;
00355       else {
00356         maxVal = c>maxVal ? c : maxVal;
00357       }
00358     }  
00359   
00360     /* }}} */
00361 
00363 
00369     ICLCore_API std::vector<double> mean(const ImgBase *poImg, int iChannel = -1, bool roiOnly = false);
00370 
00372 
00379     ICLCore_API std::vector<double> variance(const ImgBase *poImg, const std::vector<double> &mean, bool empiricMean = true, int iChannel = -1, bool roiOnly = false);
00380     
00382 
00387     ICLCore_API std::vector<double> variance(const ImgBase *poImg, int iChannel = -1, bool roiOnly = false);
00388 
00390 
00394     ICLCore_API std::vector<double> stdDeviation(const ImgBase *poImage, int iChannel = -1, bool roiOnly = false);
00395     
00397 
00403     ICLCore_API std::vector<double> stdDeviation(const ImgBase *poImage, const std::vector<double> mean, bool empiricMean = true, int iChannel = -1, bool roiOnly = false);
00404   
00406 
00411     ICLCore_API std::vector< std::pair<double, double> > meanAndStdDev(const ImgBase *image, int iChannel = -1, bool roiOnly = false);
00412     
00413     
00415     ICLCore_API std::vector<int> channelHisto(const ImgBase *image, int channel, int levels = 256, bool roiOnly = false);
00416     
00418     ICLCore_API std::vector<std::vector<int> > hist(const ImgBase *image, int levels = 256, bool roiOnly = false);
00419   
00420   } // namespace core
00421 } // namespace icl
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines