Image Component Library (ICL)
ImgBase.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/ImgBase.h **
10 ** Module : ICLCore **
11 ** Authors: Christof Elbrechter, Michael Goetting, Robert **
12 ** Haschke, Andre Justus **
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/CompatMacros.h>
35 #include <ICLCore/CoreFunctions.h>
36 #include <ICLCore/ImgParams.h>
37 #include <ICLUtils/Time.h>
38 #include <ICLUtils/Range.h>
39 #include <ICLUtils/SmartPtr.h>
40 #include <vector>
41 #include <string>
42 
43 namespace icl {
44  namespace core{
45 
47 
132  public:
133 
135  virtual ~ImgBase();
136 
150  virtual ImgBase *shallowCopy(const utils::Rect &roi,
151  const std::vector<int> &channelIndices,
152  format fmt,
154  ImgBase **ppoDst = NULL) = 0;
155 
169  const std::vector<int> &channelIndices,
170  format fmt,
171  utils::Time time=utils::Time::null) const{
172  // casting constness away is safe, because we effectively return a const Img<Type>*
173  return const_cast<ImgBase*>(this)->shallowCopy(roi,channelIndices,fmt,time,0);
174  }
175 
176 
178 
183  ImgBase *reinterpretChannels(format newFmt, ImgBase **ppoDst = NULL){
184  return shallowCopy(getROI(),std::vector<int>(),newFmt,getTime(),ppoDst);
185  }
186 
187 
189 
193  const ImgBase *reinterpretChannels(format newFmt) const{
194  // casting constness away is safe, because we effectively return a const Img<Type>*
195  return const_cast<ImgBase*>(this)->shallowCopy(getROI(),std::vector<int>(),newFmt,getTime());
196  }
198 
209  ImgBase* shallowCopy(const utils::Rect &roi, ImgBase** ppoDst = NULL){
210  return shallowCopy(roi,std::vector<int>(),getFormat(),getTime(),ppoDst);
211  }
212  ImgBase* shallowCopy(ImgBase** ppoDst = NULL){
213  return shallowCopy(getROI(),std::vector<int>(),getFormat(),getTime(),ppoDst);
214  }
215 
217 
226  const ImgBase* shallowCopy(const utils::Rect& roi) const {
227  // casting constness away is safe, because we effectively return a const Img<Type>*
228  return const_cast<ImgBase*>(this)->shallowCopy(roi,0);
229  }
230 
231 
233 
242  ImgBase* selectChannels (const std::vector<int>& channelIndices, ImgBase** ppoDst=0){
243  return shallowCopy(getROI(),channelIndices,formatMatrix,getTime(),ppoDst);
244  }
245 
247 
254  ImgBase* selectChannel(int channelIndex, ImgBase **ppoDst=0){
255  ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0);
256  std::vector<int> v(1); v[0]= channelIndex;
257  return selectChannels(v,ppoDst);
258  }
260 
263  const ImgBase* selectChannels (const std::vector<int>& channelIndices) const {
264  // casting constness away is safe, because we effectively return a const Img<Type>*
265  return const_cast<ImgBase*>(this)->selectChannels(channelIndices, 0);
266  }
267 
269 
275  const ImgBase *selectChannel(int channelIndex) const{
276  ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0);
277  std::vector<int> v(1); v[0]= channelIndex; return selectChannels(v);
278  }
279 
281 
290  virtual ImgBase *deepCopy(ImgBase **ppoDst=0) const=0;
291 
293 
302  virtual ImgBase *deepCopyROI(ImgBase **ppoDst=0) const=0;
303 
305 
319  template<class T> ICLCore_API
320  Img<T> *convert(Img<T> *poDst=NULL) const;
321 
323 
329  ImgBase *convert(depth d) const;
330 
332 
335  ImgBase *convert(ImgBase *poDst) const;
336 
338 
343  template<class T> ICLCore_API
344  Img<T> *convertROI(Img<T> *poDst=NULL) const;
345 
347 
352  ImgBase *convertROI(depth d) const;
353 
354 
356 
362  ImgBase *convertROI(ImgBase *poDst) const;
363 
365 
369  virtual ImgBase *scaledCopy(const utils::Size &newSize,
370  scalemode eScaleMode=interpolateNN) const = 0;
371 
373 
381  virtual ImgBase *scaledCopy(ImgBase **ppoDst=0,
382  scalemode eScaleMode=interpolateNN) const = 0;
383 
385 
391  virtual ImgBase *scaledCopyROI(const utils::Size &newSize,
392  scalemode eScaleMode=interpolateNN) const = 0;
393 
395 
401  virtual ImgBase *scaledCopyROI(ImgBase **ppoDst=0,
402  scalemode eScaleMode=interpolateNN) const = 0;
403 
405 
407 
416  template <class T>
418  ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == this->getDepth(), 0);
419  return reinterpret_cast<Img<T>*>(this);
420  }
421 
423 
426  template <class T>
427  const Img<T> *asImg() const {
428  ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == getDepth(), 0);
429  return reinterpret_cast<const Img<T>*>(this);
430  }
431 
433  inline Img<icl8u> *as8u() { return asImg<icl8u>(); }
434 
436  inline Img<icl16s> *as16s() { return asImg<icl16s>(); }
437 
439  inline Img<icl32s> *as32s() { return asImg<icl32s>(); }
440 
442  inline Img<icl32f> *as32f() { return asImg<icl32f>(); }
443 
445  inline Img<icl64f> *as64f() { return asImg<icl64f>(); }
446 
447 
449  inline const Img<icl8u> *as8u() const { return asImg<icl8u>(); }
450 
452  inline const Img<icl16s> *as16s() const { return asImg<icl16s>(); }
453 
455  inline const Img<icl32s> *as32s() const { return asImg<icl32s>(); }
456 
458  inline const Img<icl32f> *as32f() const { return asImg<icl32f>(); }
459 
461  inline const Img<icl64f> *as64f() const { return asImg<icl64f>(); }
462 
464 
467 
473  const ImgParams &getParams() const{ return m_oParams; }
475 
476  // returns the images size
477  const utils::Size& getSize() const { return m_oParams.getSize(); }
478 
480  int getWidth() const { return m_oParams.getWidth(); }
481 
483  int getHeight() const { return m_oParams.getHeight(); }
484 
486  int getDim() const { return m_oParams.getDim(); }
487 
489  int getChannels() const { return m_oParams.getChannels(); }
490 
492  depth getDepth() const { return m_eDepth; }
493 
495  format getFormat() const { return m_oParams.getFormat(); }
496 
498  utils::Time getTime() const { return m_timestamp; }
499 
501 
503  virtual int getLineStep() const = 0;
504 
505 
506 
508 
511  const utils::Rect &getROI() const{ return m_oParams.getROI(); }
513 
515  void getROI(utils::Point& offset, utils::Size& size) const { m_oParams.getROI(offset,size); }
516 
518  utils::Point getROIOffset() const{ return m_oParams.getROIOffset(); }
519 
521  utils::Size getROISize() const{ return m_oParams.getROISize(); }
522 
524  int getROIWidth() const{ return m_oParams.getROIWidth(); }
525 
527  int getROIHeight() const{ return m_oParams.getROIHeight(); }
528 
530  int getROIXOffset() const{ return m_oParams.getROIXOffset(); }
531 
533  int getROIYOffset() const{ return m_oParams.getROIYOffset(); }
534 
537 
539  void setROIOffset(const utils::Point &offset) { m_oParams.setROIOffset(offset); }
540 
542  void setROISize(const utils::Size &size) { m_oParams.setROISize(size); }
543 
545  void setROI(const utils::Point &offset, const utils::Size &size){ m_oParams.setROI(offset,size); }
546 
548  void setROI(const utils::Rect &roi) { m_oParams.setROI(roi); }
549 
551 
552  void setROIOffsetAdaptive(const utils::Point &offset) { m_oParams.setROIOffsetAdaptive(offset); }
553 
555 
556  void setROISizeAdaptive(const utils::Size &size){ m_oParams.setROISizeAdaptive(size); }
557 
559 
560  void setROIAdaptive(const utils::Rect &roi) { m_oParams.setROIAdaptive(roi); }
561 
563  int hasFullROI() const { return m_oParams.hasFullROI(); }
564 
566  void setFullROI() { m_oParams.setFullROI(); }
567 
569 
570 
573 
578  virtual void fillBorder(bool setFullROI=true)=0;
579 
581  virtual void fillBorder(icl64f val, bool setFullROI=true)=0;
582 
584 
587  virtual void fillBorder(const std::vector<icl64f> &vals, bool setFullROI=true)=0;
588 
589 
591 
595  virtual void fillBorder(const ImgBase *src, bool setFullROI=true)=0;
596 
598 
602 
604  virtual const void* getDataPtr(int iChannel) const = 0;
605 
607 
608  virtual void* getDataPtr(int iChannel) = 0;
609 
611 
612 
615 
621  virtual void detach(int iIndex = -1)=0;
622 
624 
632  virtual void removeChannel(int iChannel)=0;
633 
635 
640  virtual void swapChannels(int iIndexA, int iIndexB)=0;
641 
642 
644  void setParams(const ImgParams &params);
645 
647 
658  virtual void setChannels(int iNewNumChannels)=0;
659 
661 
672  virtual void setSize(const utils::Size &s)=0;
673 
675 
683  void setFormat(format fmt);
684 
686  void setTime(const utils::Time time) { m_timestamp = time; }
688  void setTime() { m_timestamp = utils::Time::now(); }
689 
691 
695 
700  icl64f getMax(int iChannel, utils::Point *coords=0) const;
701 
703 
707  icl64f getMin(int iChannel, utils::Point *coords=0) const;
708 
709 
711  icl64f getMin() const;
712 
714  icl64f getMax() const;
715 
717 
724  const utils::Range<icl64f> getMinMax(int iChannel,
725  utils::Point *minCoords=0,
726  utils::Point *maxCoords=0) const;
727 
729 
731  const utils::Range<icl64f> getMinMax() const;
732 
733 
735 
738 
746  virtual void scale(const utils::Size& s, scalemode eScaleMode=interpolateNN)=0;
747 
748 
750 
757  virtual void mirror(axis eAxis, bool bOnlyROI=false)=0;
758 
760 
764  void clear(int iChannel = -1, icl64f val=0, bool bROIOnly=true);
765 
767 
771  void normalizeAllChannels(const utils::Range<icl64f> &dstRange);
772 
774 
778  void normalizeChannel(int iChannel,const utils::Range<icl64f> &srcRange,
779  const utils::Range<icl64f> &dstRange);
780 
781 
783 
789  void normalizeChannel(int iChannel, const utils::Range<icl64f> &dstRange);
790 
792 
795  void normalizeImg(const utils::Range<icl64f> &srcRange,
796  const utils::Range<icl64f> &dstRange);
797 
799 
804  void normalizeImg(const utils::Range<icl64f> &dstRange);
805 
807 
810 
814  void print(const std::string sTitle="image") const;
815 
817  bool validChannel(const int iChannel) const {
818  return iChannel >= 0 && iChannel < getChannels();
819  }
820 
822 
825  bool isEqual(const utils::Size &s, int nChannels) const {
826  FUNCTION_LOG("isEqual("<<s.width<<","<< s.height << ","<< nChannels << ")");
827  return (getSize() == s) && (getChannels() == nChannels);
828  }
829 
831  bool isEqual(const ImgParams &params){
832  FUNCTION_LOG("");
833  return m_oParams == params;
834  }
835 
837  bool isEqual(const ImgParams &params, depth d){
838  FUNCTION_LOG("");
839  return m_oParams == params && getDepth() == d;
840  }
841 
843  bool isEqual(const ImgBase *otherImage){
844  FUNCTION_LOG("");
845  ICLASSERT_RETURN_VAL(otherImage,false);
846  return getParams() == otherImage->getParams() && getDepth() == otherImage->getDepth();
847  }
848 
850 
853  virtual bool isIndependent() const=0;
855 
857  inline bool hasMetaData() const { return m_metaData.length(); }
858 
860  inline void setMetaData(const std::string &data){
861  m_metaData = data;
862  }
863 
865  inline void clearMetaData(){
866  setMetaData("");
867  }
868 
870  inline const std::string &getMetaData() const {
871  return m_metaData;
872  }
873 
875  std::string &getMetaData() {
876  return m_metaData;
877  }
878 
879 
880  protected:
881 
883  ImgBase(depth d, const ImgParams& params);
884 
886 
893 
896 
899 
901  std::string m_metaData;
902  };
903 
905  ICLCore_API std::ostream &operator<<(std::ostream &s, const ImgBase &image);
906  } // namespace core
907 }
908 
class representing a range defined by min and max value
Definition: Range.h:49
const ImgParams & getParams() const
returns all params in terms of a const ImgParams reference
Definition: ImgBase.h:473
format getFormat() const
returns the current (color)-format of this image
Definition: ImgBase.h:495
int getWidth() const
returns the images width
Definition: ImgBase.h:480
void setROIOffsetAdaptive(const utils::Point &offset)
checks, eventually adapts and finally sets the image ROI size
Definition: ImgBase.h:552
const Img< T > * asImg() const
dynamically casts this image to one of its Img<T> subclasses (const version)
Definition: ImgBase.h:427
undocument this line if you encounter any issues!
Definition: Any.h:37
int getROIYOffset() const
returns the images ROI YOffset
Definition: ImgBase.h:533
ImgBase * shallowCopy(ImgBase **ppoDst=NULL)
Definition: ImgBase.h:212
ImgBase * selectChannel(int channelIndex, ImgBase **ppoDst=0)
Create a shallow copy of a single image channel of an image.
Definition: ImgBase.h:254
Img< T > * asImg()
dynamically casts this image to one of its Img<T> subclasses
Definition: ImgBase.h:417
ICLCore_API std::ostream & operator<<(std::ostream &s, const format &f)
puts a string representation of format into the given stream
const ImgBase * reinterpretChannels(format newFmt) const
Create a shallow copy of this image with a new format (const version)
Definition: ImgBase.h:193
void getROI(utils::Point &offset, utils::Size &size) const
copies the current ROI into the given offset and size references
Definition: ImgBase.h:515
ICL Time class (taken from the Ice lib)
Definition: Time.h:52
ICLQt_API ImgROI roi(ImgQ &r)
creates a ROI-struct from an image
Img< icl32f > * as32f()
convenience shortcut version for asImg<icl32f>()
Definition: ImgBase.h:442
const Img< icl32s > * as32s() const
convenience shortcut version for asImg<icl32s>()
Definition: ImgBase.h:455
Img< icl32s > * as32s()
convenience shortcut version for asImg<icl32s>()
Definition: ImgBase.h:439
bool isEqual(const ImgBase *otherImage)
checks if the image has given params and depth as another image
Definition: ImgBase.h:843
depth getDepth() const
returns the depth (depth8u or depth32f)
Definition: ImgBase.h:492
Img< icl64f > * as64f()
convenience shortcut version for asImg<icl64f>()
Definition: ImgBase.h:445
std::string m_metaData
additional information associated with this image
Definition: ImgBase.h:901
void setROISize(const utils::Size &size)
sets the image ROI size to the given value
Definition: ImgBase.h:542
bool isEqual(const ImgParams &params, depth d)
checks if the image has given params and depth
Definition: ImgBase.h:837
void setROIOffset(const utils::Point &offset)
sets the image ROI offset to the given value
Definition: ImgBase.h:539
The ImgParams class stores all image parameters .
Definition: ImgParams.h:58
void setTime(const utils::Time time)
sets the timestamp of the image
Definition: ImgBase.h:686
static Time now()
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
format
determines the color-format, that is associated with the images channels
Definition: Types.h:70
Img< icl16s > * as16s()
convenience shortcut version for asImg<icl16s>()
Definition: ImgBase.h:436
bool isEqual(const utils::Size &s, int nChannels) const
returns if two images have same size, and channel count
Definition: ImgBase.h:825
int getROIWidth() const
returns the images ROI width
Definition: ImgBase.h:524
int getROIHeight() const
returns the images ROI height
Definition: ImgBase.h:527
#define ICLASSERT_RETURN_VAL(X, VALUE)
Definition: Macros.h:148
Ipp64f icl64f
64Bit floating point type for the ICL
Definition: BasicTypes.h:52
depth m_eDepth
depth of the image (depth8 for icl8u/depth32 for icl32f)
Definition: ImgBase.h:895
Size class of the ICL.
Definition: Size.h:61
void setROI(const utils::Rect &roi)
sets the image ROI to the given rectangle
Definition: ImgBase.h:548
const std::string & getMetaData() const
returns associated meta data
Definition: ImgBase.h:870
depth getDepth()
getDepth<T> returns to depth enum associated to type T
ImgBase * reinterpretChannels(format newFmt, ImgBase **ppoDst=NULL)
Create a shallow copy of this image with a new format.
Definition: ImgBase.h:183
Img< icl8u > * as8u()
convenience shortcut version for asImg<icl8u>()
Definition: ImgBase.h:433
bool validChannel(const int iChannel) const
validate the given channel index
Definition: ImgBase.h:817
const ImgBase * selectChannels(const std::vector< int > &channelIndices) const
Create a shallow copy of selected channels of a const image.
Definition: ImgBase.h:263
void setROISizeAdaptive(const utils::Size &size)
checks, eventually adapts and finally sets the image ROI size
Definition: ImgBase.h:556
int hasFullROI() const
returns ROISize == ImageSize
Definition: ImgBase.h:563
utils::Rect getImageRect() const
returns the image rect (0,0,width, height)
Definition: ImgBase.h:536
bool isEqual(const ImgParams &params)
checks if the image has the given parameters
Definition: ImgBase.h:831
const Img< icl32f > * as32f() const
convenience shortcut version for asImg<icl32f>()
Definition: ImgBase.h:458
const Img< icl16s > * as16s() const
convenience shortcut version for asImg<icl16s>()
Definition: ImgBase.h:452
int getDim() const
returns the pixel count of each channel
Definition: ImgBase.h:486
scalemode
for scaling of Img images theses functions are provided
Definition: Types.h:84
bool hasMetaData() const
returns whether meta data has been associated to this image
Definition: ImgBase.h:857
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
void clearMetaData()
removes all meta data
Definition: ImgBase.h:865
static void scale(const int deg, xcomplex *P)
Definition: PolynomialSolver.h:133
ImgParams m_oParams
all image params
Definition: ImgBase.h:892
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
static const Point null
null Point is x=0, y=0
Definition: Point.h:61
int getROIXOffset() const
returns the images ROI XOffset
Definition: ImgBase.h:530
utils::Size getROISize() const
returns the images ROI size
Definition: ImgBase.h:521
int getChannels() const
returns the channel count of the image
Definition: ImgBase.h:489
Definition: Types.h:85
ImgBase * selectChannels(const std::vector< int > &channelIndices, ImgBase **ppoDst=0)
Create a shallow copy of selected channels of an image.
Definition: ImgBase.h:242
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
const ImgBase * shallowCopy(const utils::Rect &roi) const
Create a shallow copy of a const source image.
Definition: ImgBase.h:226
ImgBase * shallowCopy(const utils::Rect &roi, ImgBase **ppoDst=NULL)
Create a shallow copy of the image.
Definition: ImgBase.h:209
const Img< icl64f > * as64f() const
convenience shortcut version for asImg<icl64f>()
Definition: ImgBase.h:461
#define FUNCTION_LOG(x)
Definition: Macros.h:123
const ImgBase * shallowCopy(const utils::Rect &roi, const std::vector< int > &channelIndices, format fmt, utils::Time time=utils::Time::null) const
Definition: ImgBase.h:168
axis
for flipping of images
Definition: Types.h:99
void setROI(const utils::Point &offset, const utils::Size &size)
set both image ROI offset and size
Definition: ImgBase.h:545
void setTime()
sets timestamp of the image to the current time
Definition: ImgBase.h:688
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
utils::Time getTime() const
returns the timestamp of the image
Definition: ImgBase.h:498
static const Time null
Definition: Time.h:59
void setMetaData(const std::string &data)
associates new meta data with this image
Definition: ImgBase.h:860
std::string & getMetaData()
returns associated meta data (unconst)
Definition: ImgBase.h:875
const ImgBase * selectChannel(int channelIndex) const
Create a shallow copy of a single image channel of a const image.
Definition: ImgBase.h:275
utils::Time m_timestamp
timestamp of the image
Definition: ImgBase.h:898
void print(const core::Img< T > &image)
print the images parameters to std::out
void setROIAdaptive(const utils::Rect &roi)
checks, eventually adapts and finally sets the image ROI size
Definition: ImgBase.h:560
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
void setFullROI()
resets the image ROI to the whole image size with offset (0,0)
Definition: ImgBase.h:566
const Img< icl8u > * as8u() const
convenience shortcut version for asImg<icl8u>()
Definition: ImgBase.h:449
int getHeight() const
returns the images height
Definition: ImgBase.h:483
utils::Point getROIOffset() const
returns the images ROI offset (upper left corner)
Definition: ImgBase.h:518
#define ICLCore_API
Definition: CompatMacros.h:174
Definition: Types.h:77
virtual ImgBase * shallowCopy(const utils::Rect &roi, const std::vector< int > &channelIndices, format fmt, utils::Time time=utils::Time::null, ImgBase **ppoDst=NULL)=0
const utils::Size & getSize() const
returns the size of the images
Definition: ImgBase.h:477