/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLCore/src/ICLCore/ImgBase.cpp ** ** Module : ICLCore ** ** Authors: Christof Elbrechter, Michael Goetting, Robert Haschke ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** 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 icl::utils; using namespace icl::math; namespace icl { namespace core{ ImgBase::ImgBase(depth d, const ImgParams ¶ms):m_oParams(params),m_eDepth(d) { } ImgBase::~ImgBase(){ FUNCTION_LOG(""); } void ImgBase::print(const std::string title) const{ 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; } } 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; } } 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::core::convert(asImg()->getData(c), \ asImg()->getData(c)+getDim(),poDst->getData(c)); \ } break; switch(getDepth()){ ICL_INSTANTIATE_ALL_DEPTHS; } #undef ICL_INSTANTIATE_DEPTH return poDst; } 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; } } 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; } } template Img *ImgBase::convertROI(Img *poDst) const{ 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; } void ImgBase::setFormat(format fmt){ FUNCTION_LOG(""); int newcc = getChannelsOfFormat(fmt); if(fmt != formatMatrix && newcc != getChannels()){ setChannels(newcc); } m_oParams.setFormat(fmt); } 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 } } 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 } } 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; } 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; } 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; } 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; } 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(); } 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(); } 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("< *ImgBase::convert(Img *poDst = NULL) const; \ template ICLCore_API Img *ImgBase::convertROI(Img *poDst = NULL) const; ICL_INSTANTIATE_ALL_DEPTHS #undef ICL_INSTANTIATE_DEPTH } // namespace core } //namespace icl