/* ImgBase.h Written by: Michael Götting and Christof Elbrechter(2006) University of Bielefeld AG Neuroinformatik {mgoettin,celbrech}@techfak.uni-bielefeld.de */ #ifndef ICLBASE_H #define ICLBASE_H #include #include #include #include namespace icl { /// ImgBase is the Image-Interface class that provides save access to underlying Img-template /* {{{ ImgBase class documentation */ /** \section Class The ImgBase class provides access to the following basic image features: - image size - channel count - depth: depth8 for icl8u or depth32 for icl32f-images - format: color-format associated with images channels (see section "Img Color Formats") - raw data: getDataPtr(int) returns image data form nth channel as void pointer. The function is implented in the inherited classes Img and Img, which also provide type-safe access functions, e.g. getData (int). \section How to use the ImgBase class. As the ImgBase is an abstract class, no ImgBase objects can be instantiated It merely provides a common interface to methods provided by the inherited class Img and Img. The following example should explain how to work with ImgBase class.
  void special_function_8(Img32f* poImg32f){...}
  void special_function_32(Img8* poImg8f){...}
  
  void generic_function(ImgBase *poImage){
     if(poImage->getDepth()==depth8u){
        special_function_8(poImage->asImg());
     }else{
        special_function_32(poImage->asImg());
     }
  }
  
Template functions can be called in an analogous way:
  template void template_function(Img *poImg){...}

  void generic_function(ImgBase *poImage){
     if(poImage->getDepth()==depth8u){
        template_function(poImage->asImg);
     }else{
        template_function(poImage->asImg);
     }
  } 
  
Many operations on the Img image class are conceptually independent on the concrete pixel type, e.g. recombining channels or resizing. For these operations the ImgBase class provides abstract or implemented methods ensuring a common and type-independent interface. For example, to resize an image, one can easily write:
  void any_function(ImgBase *poBase){
     poBase->resize(Size(256,256));
     ...
  }
  
**/ /* }}} */ class ImgBase { public: //@{ @name Destructor /* {{{ open */ /// Destructor virtual ~ImgBase(); //@} /* }}} */ //@{ @name functions for data exchange /* {{{ open */ /// creates a shallow copy of the image (shared channels). /** It exploits the given destination image if possible, i.e. if the pixel depth matches. Else this image is released and a new one is created. @param poDst destination image (if Null, a new one is created) **/ ImgBase* shallowCopy(ImgBase** ppoDst = NULL) const; /// creates a shallow copy of selected channels of this image /** @param channelIndices vector containing channel indices to copy @param poDst destination image (if Null, a new one is created)*/ ImgBase* shallowCopy(const std::vector& channelIndices, ImgBase** ppoDst = NULL) const; /// copies the image data into the destination image /** this function is implemented in the Img-template class @see Img **/ virtual ImgBase* deepCopy(ImgBase* poDst = NULL) const=0; /// copies (or scales if necessary) the image data into the destination image and performs a /** this function is implemented in the Img-template class @see Img **/ virtual ImgBase* scaledCopy(ImgBase *poDst, scalemode eScaleMode=interpolateNN) const=0; /// copies the image data in the images ROI into the destination images ROI /** this function is implemented in the Img-template class @see Img **/ virtual ImgBase *deepCopyROI(ImgBase *poDst = NULL) const=0; /// scales the image data in the image ROI into the destination images ROI /** this function is implemented in the Img-template class @see Img **/ virtual ImgBase *scaledCopyROI(ImgBase *poDst = NULL, scalemode eScaleMode=interpolateNN) const=0; /// flips the image about the given axis into the destination image (IPP-OPTIMIZED) /** this function is implemented in the Img-template class @see Img **/ virtual ImgBase *flippedCopyROI(ImgBase *poDst = NULL, axis eAxis = axisVert) const=0; //@} /* }}} */ //@{ @name getter functions /* {{{ open */ /// returns all params in terms of a const ImgParams reference /** This enables the programmer to write
          imageA.setParams(imageB.getParams());
          
*/ const ImgParams &getParams() const{ return m_oParams; } /// returns the size of the images // returns the images size const Size& getSize() const { return m_oParams.getSize(); } /// returns the pixelcount of each channel int getDim() const { return m_oParams.getDim(); } /// returns the channel count of the image int getChannels() const { return m_oParams.getChannels(); } /// returns the depth (depth8u or depth32f) depth getDepth() const { return m_eDepth; } /// returns the current (color)-format of this image format getFormat() const { return m_oParams.getFormat(); } /// returns the timestamp of the image Time getTime() const { return m_timestamp; } /// returns the lenght of an image line in bytes (width*sizeof(Type)) virtual int getLineStep() const = 0; /// returns if two images have same size, and channel count /** @param s size to test @param nChannels channel count to test **/ bool isEqual(const Size &s, int nChannels) const { FUNCTION_LOG("isEqual("< and convertTo /* {{{ open */ /// returns an Img* intstance of this image (internal: reinterpret_cast) /** @return Img* instance of this image **/ template Img *asImg() const{ return reinterpret_cast*>((void*)this); } /// returns an Img instance of this image (type-conversion or deep copy) /** If the requested type differs from the actual image type, then a type conversion is performed to transfer the image data to poDst. Else deepCopy is called, to transfer the image data. If poDst is NULL, it is created with identical parameters, except for the images depth, which is given by the template parameter T. (For developers: The convertTo function builds the base function for other higher level funtions like deepCopy. Internally it calls the icl namespace function deepCopyChannel, which decides if data has to be copied or converted.) @param poDst destination image. If NULL, then a deep copy of the current image is returned @see deepCopy */ template Img *convertTo( Img* poDst=NULL ) const; //@} /* }}} */ //@{ @name utility functions /* {{{ open */ /// prints the image to std-out /** @param sTitle optional title, that can be printed before printing the image parameters to identify the message. **/ void print(const std::string sTitle="image") const; /// validate the given channel index bool validChannel(const int iChannel) const { return iChannel >= 0 && iChannel < getChannels(); } //@} /* }}} */ protected: /* {{{ Constructor */ /// Creates an ImgBase object with specified image parameters ImgBase(depth d, const ImgParams& params); /* }}} */ /* {{{ data */ /// all image params /** the params class consists of - image size - number of image channels - image format - image ROI */ ImgParams m_oParams; /// depth of the image (depth8 for icl8u/depth32 for icl32f) depth m_eDepth; /// timestamp of the image Time m_timestamp; /* }}} */ }; } #endif