Image Component Library (ICL)
CoreFunctions.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLCore/src/ICLCore/CoreFunctions.h **
10 ** Module : ICLCore **
11 ** Authors: Christof Elbrechter, Michael Goetting, Robert **
12 ** Haschke, Andre Justus, Sergius Gaulik **
13 ** **
14 ** **
15 ** GNU LESSER GENERAL PUBLIC LICENSE **
16 ** This file may be used under the terms of the GNU Lesser General **
17 ** Public License version 3.0 as published by the **
18 ** **
19 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
20 ** included in the packaging of this file. Please review the **
21 ** following information to ensure the license requirements will **
22 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
23 ** **
24 ** The development of this software was supported by the **
25 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
26 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
27 ** Forschungsgemeinschaft (DFG) in the context of the German **
28 ** Excellence Initiative. **
29 ** **
30 ********************************************************************/
31 
32 #pragma once
33 
34 #include <ICLUtils/Macros.h>
35 #include <ICLUtils/Point32f.h>
36 #include <ICLUtils/ClippedCast.h>
37 #include <ICLUtils/PThreadFix.h>
38 #include <ICLUtils/SSEUtils.h>
39 
40 #include <ICLCore/Types.h>
41 #include <ICLCore/ImgParams.h>
42 
43 #include <string>
44 #include <cstring>
45 #include <iostream>
46 #include <vector>
47 
49 
52 namespace icl {
53  namespace core{
54 
55  /* {{{ Global functions */
56 
58 
98  ICLCore_API ImgBase *imgNew(depth d = depth8u, const ImgParams &params = ImgParams::null);
99 
101  inline ImgBase *imgNew(depth d, const utils::Size& size, format fmt,
103  return imgNew(d,ImgParams(size,fmt,roi));
104  }
105 
107  inline ImgBase *imgNew(depth d, const utils::Size& size, int channels=1,
109  return imgNew(d,ImgParams(size,channels,roi));
110  }
111 
113  inline ImgBase *imgNew(depth d, const utils::Size& size, int channels, format fmt,
115  return imgNew(d,ImgParams(size,channels,fmt,roi));
116  }
117 
118 
120 
137  ICLCore_API ImgBase *ensureDepth(ImgBase **ppoImage, depth eDepth);
138 
140  ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, depth d, const ImgParams &params);
141 
143 
155  inline ImgBase *ensureCompatible(ImgBase **dst, depth d,const utils::Size& size,int channels, const utils::Rect &roi=utils::Rect::null)
156  { return ensureCompatible(dst,d,ImgParams(size,channels,roi)); }
157 
160  { return ensureCompatible(dst,d,ImgParams(size,fmt,roi)); }
161 
163 
166  ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, depth d, const utils::Size &size, int channels, format fmt, const utils::Rect &roi = utils::Rect::null);
167 
169 
179  ICLCore_API ImgBase *ensureCompatible(ImgBase **dst, const ImgBase *src);
180 
182 
186 
188  template<class T> inline depth getDepth();
189 
190 
192  ICLCore_API std::ostream &operator<<(std::ostream &s, const format &f);
193 
195  ICLCore_API std::ostream &operator<<(std::ostream &s, const depth &d);
196 
198  ICLCore_API std::istream &operator>>(std::istream &s, format &f);
199 
201  ICLCore_API std::istream &operator>>(std::istream &s, depth &d);
202 
203 
205  #define ICL_INSTANTIATE_DEPTH(T) \
206  template<> inline depth getDepth<icl ## T>() { return depth ## T; }
208  #undef ICL_INSTANTIATE_DEPTH
209 
211  ICLCore_API unsigned int getSizeOf(depth eDepth);
213 
215  template <class T>
216  inline void copy(const T *src, const T *srcEnd, T *dst){
217  //std::copy<T>(src,srcEnd,dst);
218  memcpy(dst,src,(srcEnd-src)*sizeof(T));
219  }
220 
221 
222  #ifdef ICL_HAVE_IPP
223 
224  template <>
225  inline void copy<icl8u>(const icl8u *poSrcStart, const icl8u *poSrcEnd, icl8u *poDst){
226  ippsCopy_8u(poSrcStart,poDst,(poSrcEnd-poSrcStart));
227  }
228  template <>
229  inline void copy<icl16s>(const icl16s *poSrcStart, const icl16s *poSrcEnd, icl16s *poDst){
230  ippsCopy_16s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
231  }
232  template <>
233  inline void copy<icl32s>(const icl32s *poSrcStart, const icl32s *poSrcEnd, icl32s *poDst){
234  ippsCopy_32s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
235  }
236  template <>
237  inline void copy<icl32f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32f *poDst){
238  ippsCopy_32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
239  }
240  template <>
241  inline void copy<icl64f>(const icl64f *poSrcStart, const icl64f *poSrcEnd, icl64f *poDst){
242  ippsCopy_64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
243  }
245  #endif
246 
247 
248 
249 
251  template <class srcT,class dstT>
252  inline void convert(const srcT *poSrcStart,const srcT *poSrcEnd, dstT *poDst){
253  std::transform(poSrcStart,poSrcEnd,poDst,utils::clipped_cast<srcT,dstT>);
254  }
255 
256  #ifdef ICL_HAVE_IPP
257 
258  template<> inline void convert<icl8u,icl32f>(const icl8u *poSrcStart,const icl8u *poSrcEnd, icl32f *poDst){
260  ippsConvert_8u32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
261  }
263  template<> inline void convert<icl16s,icl32s>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32s *poDst){
264  ippsConvert_16s32s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
265  }
266  template<> inline void convert<icl16s,icl32f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32f *poDst){
267  ippsConvert_16s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
268  }
269  template<> inline void convert<icl16s,icl64f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl64f *poDst){
270  ippsConvert_16s64f_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),0);
271  }
272 
273  // from icl32s functions
274  template<> inline void convert<icl32s,icl16s>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl16s *poDst){
275  ippsConvert_32s16s(poSrcStart,poDst,(poSrcEnd-poSrcStart));
276  }
277  template<> inline void convert<icl32s,icl32f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl32f *poDst){
278  ippsConvert_32s32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
279  }
280  template<> inline void convert<icl32s,icl64f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl64f *poDst){
281  ippsConvert_32s64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
282  }
283 
284  // from icl32f functions
285  template <> inline void convert<icl32f,icl8u>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl8u *poDst){
286  ippsConvert_32f8u_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
287  }
288  template <> inline void convert<icl32f,icl16s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl16s *poDst){
289  ippsConvert_32f16s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
290  }
291  template <> inline void convert<icl32f,icl32s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32s *poDst){
292  ippsConvert_32f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
293  }
294  template <> inline void convert<icl32f,icl64f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl64f *poDst){
295  ippsConvert_32f64f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
296  }
297 
298  // from icl64f functions
299  template<> inline void convert<icl64f,icl32f>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32f *poDst){
300  ippsConvert_64f32f(poSrcStart,poDst,(poSrcEnd-poSrcStart));
301  }
302  template <> inline void convert<icl64f,icl32s>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32s *poDst){
303  ippsConvert_64f32s_Sfs(poSrcStart,poDst,(poSrcEnd-poSrcStart),ippRndNear,0);
304  }
306  #elif defined ICL_HAVE_SSE2
307 
309  template<> ICLCore_API void convert<icl8u,icl32f>(const icl8u *poSrcStart,const icl8u *poSrcEnd, icl32f *poDst);
311 
313  template<> ICLCore_API void convert<icl16s,icl32s>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32s *poDst);
314  template<> ICLCore_API void convert<icl16s,icl32f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl32f *poDst);
315  template<> ICLCore_API void convert<icl16s,icl64f>(const icl16s *poSrcStart,const icl16s *poSrcEnd, icl64f *poDst);
316 
317  // from icl32s functions
318  template<> ICLCore_API void convert<icl32s,icl16s>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl16s *poDst);
319  template<> ICLCore_API void convert<icl32s,icl32f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl32f *poDst);
320  template<> ICLCore_API void convert<icl32s,icl64f>(const icl32s *poSrcStart,const icl32s *poSrcEnd, icl64f *poDst);
321 
322  // from icl32f functions
323  template <> ICLCore_API void convert<icl32f,icl8u>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl8u *poDst);
324  template <> ICLCore_API void convert<icl32f,icl16s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl16s *poDst);
325  template <> ICLCore_API void convert<icl32f,icl32s>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl32s *poDst);
326  template <> ICLCore_API void convert<icl32f,icl64f>(const icl32f *poSrcStart, const icl32f *poSrcEnd, icl64f *poDst);
327 
328  // from icl64f functions
329  template<> ICLCore_API void convert<icl64f,icl32f>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32f *poDst);
330  template <> ICLCore_API void convert<icl64f,icl32s>(const icl64f *poSrcStart,const icl64f *poSrcEnd, icl32s *poDst);
331 
333  #endif
334 
335 
337 
343  template<class T>
344  ICLCore_API inline void getMinAndMax(T a, T b, T c, T &minVal, T &maxVal){
345  if(a<b) {
346  minVal=a;
347  maxVal=b;
348  }
349  else {
350  minVal=b;
351  maxVal=a;
352  }
353  if(c<minVal)
354  minVal=c;
355  else {
356  maxVal = c>maxVal ? c : maxVal;
357  }
358  }
359 
360  /* }}} */
361 
363 
369  ICLCore_API std::vector<double> mean(const ImgBase *poImg, int iChannel = -1, bool roiOnly = false);
370 
372 
379  ICLCore_API std::vector<double> variance(const ImgBase *poImg, const std::vector<double> &mean, bool empiricMean = true, int iChannel = -1, bool roiOnly = false);
380 
382 
387  ICLCore_API std::vector<double> variance(const ImgBase *poImg, int iChannel = -1, bool roiOnly = false);
388 
390 
394  ICLCore_API std::vector<double> stdDeviation(const ImgBase *poImage, int iChannel = -1, bool roiOnly = false);
395 
397 
403  ICLCore_API std::vector<double> stdDeviation(const ImgBase *poImage, const std::vector<double> mean, bool empiricMean = true, int iChannel = -1, bool roiOnly = false);
404 
406 
411  ICLCore_API std::vector< std::pair<double, double> > meanAndStdDev(const ImgBase *image, int iChannel = -1, bool roiOnly = false);
412 
413 
415  ICLCore_API std::vector<int> channelHisto(const ImgBase *image, int channel, int levels = 256, bool roiOnly = false);
416 
418  ICLCore_API std::vector<std::vector<int> > hist(const ImgBase *image, int levels = 256, bool roiOnly = false);
419 
420  } // namespace core
421 } // namespace icl
undocument this line if you encounter any issues!
Definition: Any.h:37
ICLCore_API std::vector< std::vector< int > > hist(const ImgBase *image, int levels=256, bool roiOnly=false)
computes the color histogramm of given image
#define ICL_INSTANTIATE_ALL_DEPTHS
Definition: Macros.h:175
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
ICLCore_API std::vector< std::pair< double, double > > meanAndStdDev(const ImgBase *image, int iChannel=-1, bool roiOnly=false)
Calculates mean and standard deviation of given image simultanously.
ICLCore_API std::istream & operator>>(std::istream &s, format &f)
puts a string representation of format into the given stream
ICLCore_API std::ostream & operator<<(std::ostream &s, const format &f)
puts a string representation of format into the given stream
ICLQt_API ImgQ levels(const ImgQ &image, icl8u levels)
reduces an images quantisation levels
ICLCore_API void getMinAndMax(T a, T b, T c, T &minVal, T &maxVal)
function, that calculates the mininum and the maximum value of three value
Definition: CoreFunctions.h:344
ICLQt_API ImgROI roi(ImgQ &r)
creates a ROI-struct from an image
ICLCore_API ImgBase * ensureDepth(ImgBase **ppoImage, depth eDepth)
ensures that an image has the specified depth
static const Rect null
null Rect is w=0, h=0, x=0, y=0
Definition: Rect.h:99
The ImgParams class stores all image parameters .
Definition: ImgParams.h:58
format
determines the color-format, that is associated with the images channels
Definition: Types.h:70
ICLCore_API ImgBase * imgNew(depth d=depth8u, const ImgParams &params=ImgParams::null)
create a new image instance of the given depth type and with given parameters
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
Ipp32f icl32f
32Bit floating point type for the ICL
Definition: BasicTypes.h:55
Definition: Types.h:61
Ipp64f icl64f
64Bit floating point type for the ICL
Definition: BasicTypes.h:52
Size class of the ICL.
Definition: Size.h:61
ICLCore_API std::vector< double > variance(const ImgBase *poImg, const std::vector< double > &mean, bool empiricMean=true, int iChannel=-1, bool roiOnly=false)
Compute the variance value of an image a with given mean.
depth getDepth()
getDepth<T> returns to depth enum associated to type T
static const ImgParams null
as default size=(0,0), channels=0, format=matrix, roi=(0,0,0,0)
Definition: ImgParams.h:61
ICLCore_API std::vector< int > channelHisto(const ImgBase *image, int channel, int levels=256, bool roiOnly=false)
computes the color histogramm of given image channel
ICLCore_API std::vector< double > mean(const ImgBase *poImg, int iChannel=-1, bool roiOnly=false)
Computes the mean value of a ImgBase* ingroup MATH.
ICLCore_API ImgBase * ensureCompatible(ImgBase **dst, depth d, const ImgParams &params)
ensures that an image has given depth and parameters
ICLCore_API std::vector< double > stdDeviation(const ImgBase *poImage, int iChannel=-1, bool roiOnly=false)
Compute the std::deviation of an image.
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
ICLCore_API unsigned int getSizeOf(depth eDepth)
return sizeof value for the given depth type
void convert(const srcT *poSrcStart, const srcT *poSrcEnd, dstT *poDst)
moves value from source to destination array (with casting on demand)
Definition: CoreFunctions.h:252
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
ICLCore_API int getChannelsOfFormat(format fmt)
determines the count of channels, for each color format
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
ICLQt_API ImgQ channel(const ImgQ &image, int channel)
picks a specific image channel
Ipp16s icl16s
16bit signed integer type for the ICL (range [-32767, 32768 ])
Definition: BasicTypes.h:61
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
#define ICLCore_API
Definition: CompatMacros.h:174