/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2012 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLCore/src/ImgBase.cpp ** ** Module : ICLCore ** ** Authors: Christof Elbrechter, Michael Götting, Robert Haschke ** ** ** ** ** ** Commercial License ** ** ICL can be used commercially, please refer to our website ** ** www.iclcv.org for more details. ** ** ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the ** ** GNU General Public License version 3.0 as published by the ** ** Free Software Foundation and appearing in the file LICENSE.GPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the GNU General Public License ** ** version 3.0 requirements will be met: ** ** http://www.gnu.org/copyleft/gpl.html. ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** *********************************************************************/ #include #include #include using namespace std; namespace icl { // {{{ constructor / destructor ImgBase::ImgBase(depth d, const ImgParams ¶ms):m_oParams(params),m_eDepth(d) { // {{{ open FUNCTION_LOG("ImgBase(" << getWidth() << "," << getHeight() << "," << translateFormat(getFormat()) << ", "<< translateDepth(getDepth()) << "," << getChannels() << ") this:" << this); } // }}} ImgBase::~ImgBase(){ // {{{ open FUNCTION_LOG(""); } // }}} // }}} // {{{ utility functions void ImgBase::print(const string title) const{ // {{{ open FUNCTION_LOG(sTitle); std::cout << " -----------------------------------------" << std::endl << "| image : " << title << std::endl << "| timestamp : " << getTime() << std::endl << "| size : " << getSize() << std::endl << "| channels : " << getChannels() << std::endl << "| depth : " << getDepth() << std::endl << "| format : " << getFormat() << std::endl << "| roi : " << (hasFullROI() ? str("full") : str(getROI())) << std::endl << " -----------------------------------------" << std::endl; for(int i=0;iconvert((Img*)0); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convert(ImgBase *poDst) ImgBase *ImgBase::convert(ImgBase *poDst) const{ FUNCTION_LOG(""); if(!poDst) return deepCopy(); switch(poDst->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convert(poDst->asImg()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convert(Img*) template Img *ImgBase::convert(Img *poDst) const{ FUNCTION_LOG("ptr:"<(getParams()); else poDst->setParams(getParams()); poDst->setTime(getTime()); poDst->setMetaData(getMetaData()); #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: for(int c=getChannels()-1;c>=0;--c){ \ icl::convert(asImg()->getData(c), \ asImg()->getData(c)+getDim(),poDst->getData(c)); \ } break; switch(getDepth()){ ICL_INSTANTIATE_ALL_DEPTHS; } #undef ICL_INSTANTIATE_DEPTH return poDst; } // }}} // {{{ convertROI(depth) ImgBase *ImgBase::convertROI(depth d) const{ FUNCTION_LOG(""); switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convertROI((Img*)0); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convertROI(ImgBase *) ImgBase *ImgBase::convertROI(ImgBase *poDst) const{ FUNCTION_LOG(""); if(!poDst) return deepCopy(); switch(poDst->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convertROI(poDst->asImg()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convertROI(Img*) template Img *ImgBase::convertROI(Img *poDst) const{ /// new using src and dst ROI FUNCTION_LOG("ptr:"<(getROISize(),getChannels(),getFormat()); }else{ ICLASSERT( poDst->getROISize() == getROISize() ); poDst->setChannels(getChannels()); poDst->setFormat(getFormat()); } poDst->setTime(getTime()); poDst->setMetaData(getMetaData()); #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: \ for(int c=getChannels()-1;c>=0;--c){ \ convertChannelROI(asImg(),c,getROIOffset(),getROISize(), \ poDst,c,poDst->getROIOffset(),poDst->getROISize()); \ } \ break; switch(getDepth()){ ICL_INSTANTIATE_ALL_DEPTHS; } #undef ICL_INSTANTIATE_DEPTH return poDst; } // }}} // {{{ setFormat void ImgBase::setFormat(format fmt){ FUNCTION_LOG(""); int newcc = getChannelsOfFormat(fmt); if(fmt != formatMatrix && newcc != getChannels()){ setChannels(newcc); } m_oParams.setFormat(fmt); } // }}} // {{{ clear void ImgBase::clear(int iChannel, icl64f val, bool bROIOnly){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: \ asImg()->clear(iChannel, \ clipped_cast(val), \ bROIOnly); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} // {{{ normalizeXXX void ImgBase::normalizeAllChannels(const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeAllChannels( \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeChannel(int iChannel,const Range &srcRange,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeChannel(iChannel, \ srcRange.castTo(), \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeChannel(int iChannel,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeChannel(iChannel, \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeImg(const Range &srcRange,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeImg( \ srcRange.castTo(), \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeImg(const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeImg( \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} // {{{ getMin,getMax, getMinMax icl64f ImgBase::getMax(int iChannel, Point *coords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMax(iChannel,coords); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// Returns min pixel value of channel iChannel within ROI /** @param iChannel Index of channel **/ icl64f ImgBase::getMin(int iChannel, Point *coords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMin(iChannel,coords); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// return maximal pixel value over all channels (restricted to ROI) icl64f ImgBase::getMin() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMin(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// return minimal pixel value over all channels (restricted to ROI) icl64f ImgBase::getMax() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMax(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// Returns min and max pixel values of channel iChannel within ROI /** @param rtMin reference to store the min value @param rtMax reference to store the max value @param iChannel Index of channel **/ const Range ImgBase::getMinMax(int iChannel, Point *minCoords, Point *maxCoords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMinMax(iChannel,minCoords,maxCoords).castTo(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return Range(); } /// return minimal and maximal pixel values over all channels (restricted to ROI) const Range ImgBase::getMinMax() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMinMax().castTo(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return Range(); } // }}} // {{{ setParams void ImgBase::setParams(const ImgParams ¶ms){ FUNCTION_LOG(""); setChannels(params.getChannels()); setSize(params.getSize()); setFormat(params.getFormat()); setROI(params.getROI()); } // }}} std::ostream &operator<<(std::ostream &s, const ImgBase &image){ return s << "Img<" << image.getDepth() << ">(Size("<