Image Component Library (ICL)
|
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 ** 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.GPL ** 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 <string> 00035 #include <cstring> 00036 #include <iostream> 00037 #include <vector> 00038 00039 #include <ICLUtils/Macros.h> 00040 #include <ICLUtils/Point32f.h> 00041 #include <ICLUtils/ClippedCast.h> 00042 #include <ICLUtils/PThreadFix.h> 00043 00044 #include <ICLCore/Types.h> 00045 #include <ICLCore/ImgParams.h> 00046 00048 00051 namespace icl { 00052 namespace core{ 00053 00054 /* {{{ Global functions */ 00055 00057 00097 ImgBase *imgNew(depth d=depth8u, const ImgParams ¶ms = ImgParams::null); 00098 00100 inline ImgBase *imgNew(depth d, const utils::Size& size, format fmt, 00101 const utils::Rect &roi=utils::Rect::null){ 00102 return imgNew(d,ImgParams(size,fmt,roi)); 00103 } 00104 00106 inline ImgBase *imgNew(depth d, const utils::Size& size, int channels=1, 00107 const utils::Rect &roi=utils::Rect::null){ 00108 return imgNew(d,ImgParams(size,channels,roi)); 00109 } 00110 00112 inline ImgBase *imgNew(depth d, const utils::Size& size, int channels, format fmt, 00113 const utils::Rect &roi=utils::Rect::null){ 00114 return imgNew(d,ImgParams(size,channels,fmt,roi)); 00115 } 00116 00117 00119 00136 ImgBase *ensureDepth(ImgBase **ppoImage, depth eDepth); 00137 00139 ImgBase *ensureCompatible(ImgBase **dst, depth d,const ImgParams ¶ms); 00140 00142 00154 inline ImgBase *ensureCompatible(ImgBase **dst, depth d,const utils::Size& size,int channels, const utils::Rect &roi=utils::Rect::null) 00155 { return ensureCompatible(dst,d,ImgParams(size,channels,roi)); } 00156 00158 inline ImgBase *ensureCompatible(ImgBase **dst, depth d,const utils::Size& size, format fmt, const utils::Rect &roi=utils::Rect::null) 00159 { return ensureCompatible(dst,d,ImgParams(size,fmt,roi)); } 00160 00162 00165 ImgBase *ensureCompatible(ImgBase **dst, depth d, const utils::Size &size, int channels, format fmt, const utils::Rect &roi=utils::Rect::null); 00166 00168 00178 ImgBase *ensureCompatible(ImgBase **dst, const ImgBase *src); 00179 00181 00184 int getChannelsOfFormat(format fmt); 00185 00187 template<class T> inline depth getDepth(); 00188 00189 00191 std::ostream &operator<<(std::ostream &s,const format &f); 00192 00194 std::ostream &operator<<(std::ostream &s,const depth &d); 00195 00197 std::istream &operator>>(std::istream &s, format &f); 00198 00200 std::istream &operator>>(std::istream &s, depth &d); 00201 00202 00204 #define ICL_INSTANTIATE_DEPTH(T) \ 00205 template<> inline depth getDepth<icl ## T>() { return depth ## T; } 00206 ICL_INSTANTIATE_ALL_DEPTHS 00207 #undef ICL_INSTANTIATE_DEPTH 00208 00210 00211 unsigned int getSizeOf(depth eDepth); 00212 00214 template <class T> 00215 inline void copy(const T *src, const T *srcEnd, T *dst){ 00216 //std::copy<T>(src,srcEnd,dst); 00217 memcpy(dst,src,(srcEnd-src)*sizeof(T)); 00218 } 00219 00220 00221 #ifdef HAVE_IPP 00222 00223 template <> 00224 inline void copy<icl8u>(const icl8u *poSrcStart, const icl8u *poSrcEnd, icl8u *poDst){ 00225 ippsCopy_8u(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00226 } 00227 template <> 00228 inline void copy<icl16s>(const icl16s *poSrcStart, const icl16s *poSrcEnd, icl16s *poDst){ 00229 ippsCopy_16s(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00230 } 00231 template <> 00232 inline void copy<icl32s>(const icl32s *poSrcStart, const icl32s *poSrcEnd, icl32s *poDst){ 00233 ippsCopy_32s(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00234 } 00235 template <> 00236 inline void copy<icl32f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32f *poDst){ 00237 ippsCopy_32f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00238 } 00239 template <> 00240 inline void copy<icl64f>(const icl64f *poSrcStart, const icl64f *poSrcEnd, icl64f *poDst){ 00241 ippsCopy_64f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00242 } 00244 #endif 00245 00246 00247 00248 00250 template <class srcT,class dstT> 00251 inline void convert(const srcT *poSrcStart,const srcT *poSrcEnd, dstT *poDst){ 00252 std::transform(poSrcStart,poSrcEnd,poDst,utils::clipped_cast<srcT,dstT>); 00253 } 00254 00255 #ifdef HAVE_IPP 00256 00257 00258 template<> inline void convert<icl8u,icl32f>(const icl8u *poSrcStart,const icl8u *poSrcEnd, icl32f *poDst){ 00259 ippsConvert_8u32f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00260 } 00262 template<> inline void convert<icl16s,icl32s>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32s *poDst){ 00263 ippsConvert_16s32s(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00264 } 00265 template<> inline void convert<icl16s,icl32f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32f *poDst){ 00266 ippsConvert_16s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00267 } 00268 template<> inline void convert<icl16s,icl64f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl64f *poDst){ 00269 ippsConvert_16s64f_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),0); 00270 } 00271 00272 // from icl32s functions 00273 template<> inline void convert<icl32s,icl16s>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl16s *poDst){ 00274 ippsConvert_32s16s(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00275 } 00276 template<> inline void convert<icl32s,icl32f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl32f *poDst){ 00277 ippsConvert_32s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00278 } 00279 template<> inline void convert<icl32s,icl64f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl64f *poDst){ 00280 ippsConvert_32s64f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00281 } 00282 00283 // from icl32f functions 00284 template <> inline void convert<icl32f,icl8u>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl8u *poDst){ 00285 ippsConvert_32f8u_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0); 00286 } 00287 template <> inline void convert<icl32f,icl16s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl16s *poDst){ 00288 ippsConvert_32f16s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0); 00289 } 00290 template <> inline void convert<icl32f,icl32s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32s *poDst){ 00291 ippsConvert_32f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0); 00292 } 00293 template <> inline void convert<icl32f,icl64f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl64f *poDst){ 00294 ippsConvert_32f64f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00295 } 00296 00297 // from icl64f functions 00298 template<> inline void convert<icl64f,icl32f>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32f *poDst){ 00299 ippsConvert_64f32f(poSrcStart,poDst,(poSrcEnd-poSrcStart)); 00300 } 00301 template <> inline void convert<icl64f,icl32s>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32s *poDst){ 00302 ippsConvert_64f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0); 00303 } 00305 #endif 00306 00307 00308 00310 00316 template<class T> 00317 inline void getMinAndMax(T a, T b, T c, T &minVal, T &maxVal){ 00318 if(a<b) { 00319 minVal=a; 00320 maxVal=b; 00321 } 00322 else { 00323 minVal=b; 00324 maxVal=a; 00325 } 00326 if(c<minVal) 00327 minVal=c; 00328 else { 00329 maxVal = c>maxVal ? c : maxVal; 00330 } 00331 } 00332 00333 /* }}} */ 00334 00336 00342 std::vector<double> mean(const ImgBase *poImg, int iChannel=-1, bool roiOnly=false); 00343 00345 00352 std::vector<double> variance(const ImgBase *poImg, const std::vector<double> &mean, bool empiricMean=true, int iChannel=-1, bool roiOnly=false); 00353 00355 00360 std::vector<double> variance(const ImgBase *poImg, int iChannel=-1, bool roiOnly=false); 00361 00363 00367 std::vector<double> stdDeviation(const ImgBase *poImage, int iChannel=-1, bool roiOnly = false); 00368 00370 00376 std::vector<double> stdDeviation(const ImgBase *poImage, const std::vector<double> mean, bool empiricMean=true, int iChannel=-1, bool roiOnly = false); 00377 00379 00384 std::vector< std::pair<double,double> > meanAndStdDev(const ImgBase *image, int iChannel=-1, bool roiOnly = false); 00385 00386 00388 std::vector<int> channelHisto(const ImgBase *image,int channel, int levels=256, bool roiOnly=false); 00389 00391 std::vector<std::vector<int> > hist(const ImgBase *image, int levels=256, bool roiOnly=false); 00392 00393 } // namespace core 00394 } // namespace icl