Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLCore/src/ICLCore/ImgBase.h ** 00010 ** Module : ICLCore ** 00011 ** Authors: Christof Elbrechter, Michael Goetting, Robert ** 00012 ** Haschke, Andre Justus ** 00013 ** ** 00014 ** ** 00015 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00016 ** This file may be used under the terms of the GNU Lesser General ** 00017 ** Public License version 3.0 as published by the ** 00018 ** ** 00019 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00020 ** included in the packaging of this file. Please review the ** 00021 ** following information to ensure the license requirements will ** 00022 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00023 ** ** 00024 ** The development of this software was supported by the ** 00025 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00026 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00027 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00028 ** Excellence Initiative. ** 00029 ** ** 00030 ********************************************************************/ 00031 00032 #pragma once 00033 00034 #include <ICLUtils/CompatMacros.h> 00035 #include <ICLCore/CoreFunctions.h> 00036 #include <ICLCore/ImgParams.h> 00037 #include <ICLUtils/Time.h> 00038 #include <ICLUtils/Range.h> 00039 #include <ICLUtils/SmartPtr.h> 00040 #include <vector> 00041 #include <string> 00042 00043 namespace icl { 00044 namespace core{ 00045 00047 00131 class ICLCore_API ImgBase{ 00132 public: 00133 00135 virtual ~ImgBase(); 00136 00150 virtual ImgBase *shallowCopy(const utils::Rect &roi, 00151 const std::vector<int> &channelIndices, 00152 format fmt, 00153 utils::Time time=utils::Time::null, 00154 ImgBase **ppoDst = NULL) = 0; 00155 00168 const ImgBase *shallowCopy(const utils::Rect &roi, 00169 const std::vector<int> &channelIndices, 00170 format fmt, 00171 utils::Time time=utils::Time::null) const{ 00172 // casting constness away is safe, because we effectively return a const Img<Type>* 00173 return const_cast<ImgBase*>(this)->shallowCopy(roi,channelIndices,fmt,time,0); 00174 } 00175 00176 00178 00183 ImgBase *reinterpretChannels(format newFmt, ImgBase **ppoDst = NULL){ 00184 return shallowCopy(getROI(),std::vector<int>(),newFmt,getTime(),ppoDst); 00185 } 00186 00187 00189 00193 const ImgBase *reinterpretChannels(format newFmt) const{ 00194 // casting constness away is safe, because we effectively return a const Img<Type>* 00195 return const_cast<ImgBase*>(this)->shallowCopy(getROI(),std::vector<int>(),newFmt,getTime()); 00196 } 00198 00209 ImgBase* shallowCopy(const utils::Rect &roi, ImgBase** ppoDst = NULL){ 00210 return shallowCopy(roi,std::vector<int>(),getFormat(),getTime(),ppoDst); 00211 } 00212 ImgBase* shallowCopy(ImgBase** ppoDst = NULL){ 00213 return shallowCopy(getROI(),std::vector<int>(),getFormat(),getTime(),ppoDst); 00214 } 00215 00217 00226 const ImgBase* shallowCopy(const utils::Rect& roi) const { 00227 // casting constness away is safe, because we effectively return a const Img<Type>* 00228 return const_cast<ImgBase*>(this)->shallowCopy(roi,0); 00229 } 00230 00231 00233 00242 ImgBase* selectChannels (const std::vector<int>& channelIndices, ImgBase** ppoDst=0){ 00243 return shallowCopy(getROI(),channelIndices,formatMatrix,getTime(),ppoDst); 00244 } 00245 00247 00254 ImgBase* selectChannel(int channelIndex, ImgBase **ppoDst=0){ 00255 ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0); 00256 std::vector<int> v(1); v[0]= channelIndex; 00257 return selectChannels(v,ppoDst); 00258 } 00260 00263 const ImgBase* selectChannels (const std::vector<int>& channelIndices) const { 00264 // casting constness away is safe, because we effectively return a const Img<Type>* 00265 return const_cast<ImgBase*>(this)->selectChannels(channelIndices, 0); 00266 } 00267 00269 00275 const ImgBase *selectChannel(int channelIndex) const{ 00276 ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0); 00277 std::vector<int> v(1); v[0]= channelIndex; return selectChannels(v); 00278 } 00279 00281 00282 00290 virtual ImgBase *deepCopy(ImgBase **ppoDst=0) const=0; 00291 00293 00302 virtual ImgBase *deepCopyROI(ImgBase **ppoDst=0) const=0; 00303 00305 00319 template<class T> ICLCore_API 00320 Img<T> *convert(Img<T> *poDst=NULL) const; 00321 00323 00329 ImgBase *convert(depth d) const; 00330 00332 00335 ImgBase *convert(ImgBase *poDst) const; 00336 00338 00343 template<class T> ICLCore_API 00344 Img<T> *convertROI(Img<T> *poDst=NULL) const; 00345 00347 00352 ImgBase *convertROI(depth d) const; 00353 00354 00356 00362 ImgBase *convertROI(ImgBase *poDst) const; 00363 00365 00369 virtual ImgBase *scaledCopy(const utils::Size &newSize, 00370 scalemode eScaleMode=interpolateNN) const = 0; 00371 00373 00381 virtual ImgBase *scaledCopy(ImgBase **ppoDst=0, 00382 scalemode eScaleMode=interpolateNN) const = 0; 00383 00385 00391 virtual ImgBase *scaledCopyROI(const utils::Size &newSize, 00392 scalemode eScaleMode=interpolateNN) const = 0; 00393 00395 00401 virtual ImgBase *scaledCopyROI(ImgBase **ppoDst=0, 00402 scalemode eScaleMode=interpolateNN) const = 0; 00403 00405 00407 00408 00416 template <class T> 00417 Img<T> *asImg() { 00418 ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == this->getDepth(), 0); 00419 return reinterpret_cast<Img<T>*>(this); 00420 } 00421 00423 00426 template <class T> 00427 const Img<T> *asImg() const { 00428 ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == getDepth(), 0); 00429 return reinterpret_cast<const Img<T>*>(this); 00430 } 00431 00433 inline Img<icl8u> *as8u() { return asImg<icl8u>(); } 00434 00436 inline Img<icl16s> *as16s() { return asImg<icl16s>(); } 00437 00439 inline Img<icl32s> *as32s() { return asImg<icl32s>(); } 00440 00442 inline Img<icl32f> *as32f() { return asImg<icl32f>(); } 00443 00445 inline Img<icl64f> *as64f() { return asImg<icl64f>(); } 00446 00447 00449 inline const Img<icl8u> *as8u() const { return asImg<icl8u>(); } 00450 00452 inline const Img<icl16s> *as16s() const { return asImg<icl16s>(); } 00453 00455 inline const Img<icl32s> *as32s() const { return asImg<icl32s>(); } 00456 00458 inline const Img<icl32f> *as32f() const { return asImg<icl32f>(); } 00459 00461 inline const Img<icl64f> *as64f() const { return asImg<icl64f>(); } 00462 00464 00467 00468 00473 const ImgParams &getParams() const{ return m_oParams; } 00475 00476 // returns the images size 00477 const utils::Size& getSize() const { return m_oParams.getSize(); } 00478 00480 int getWidth() const { return m_oParams.getWidth(); } 00481 00483 int getHeight() const { return m_oParams.getHeight(); } 00484 00486 int getDim() const { return m_oParams.getDim(); } 00487 00489 int getChannels() const { return m_oParams.getChannels(); } 00490 00492 depth getDepth() const { return m_eDepth; } 00493 00495 format getFormat() const { return m_oParams.getFormat(); } 00496 00498 utils::Time getTime() const { return m_timestamp; } 00499 00501 00503 virtual int getLineStep() const = 0; 00504 00505 00506 00508 00511 00512 const utils::Rect &getROI() const{ return m_oParams.getROI(); } 00513 00515 void getROI(utils::Point& offset, utils::Size& size) const { m_oParams.getROI(offset,size); } 00516 00518 utils::Point getROIOffset() const{ return m_oParams.getROIOffset(); } 00519 00521 utils::Size getROISize() const{ return m_oParams.getROISize(); } 00522 00524 int getROIWidth() const{ return m_oParams.getROIWidth(); } 00525 00527 int getROIHeight() const{ return m_oParams.getROIHeight(); } 00528 00530 int getROIXOffset() const{ return m_oParams.getROIXOffset(); } 00531 00533 int getROIYOffset() const{ return m_oParams.getROIYOffset(); } 00534 00536 utils::Rect getImageRect() const { return utils::Rect(utils::Point::null,getSize()); } 00537 00539 void setROIOffset(const utils::Point &offset) { m_oParams.setROIOffset(offset); } 00540 00542 void setROISize(const utils::Size &size) { m_oParams.setROISize(size); } 00543 00545 void setROI(const utils::Point &offset, const utils::Size &size){ m_oParams.setROI(offset,size); } 00546 00548 void setROI(const utils::Rect &roi) { m_oParams.setROI(roi); } 00549 00551 00552 void setROIOffsetAdaptive(const utils::Point &offset) { m_oParams.setROIOffsetAdaptive(offset); } 00553 00555 00556 void setROISizeAdaptive(const utils::Size &size){ m_oParams.setROISizeAdaptive(size); } 00557 00559 00560 void setROIAdaptive(const utils::Rect &roi) { m_oParams.setROIAdaptive(roi); } 00561 00563 int hasFullROI() const { return m_oParams.hasFullROI(); } 00564 00566 void setFullROI() { m_oParams.setFullROI(); } 00567 00569 00570 00573 00574 00578 virtual void fillBorder(bool setFullROI=true)=0; 00579 00581 virtual void fillBorder(icl64f val, bool setFullROI=true)=0; 00582 00584 00587 virtual void fillBorder(const std::vector<icl64f> &vals, bool setFullROI=true)=0; 00588 00589 00591 00595 virtual void fillBorder(const ImgBase *src, bool setFullROI=true)=0; 00596 00598 00602 00603 00604 virtual const void* getDataPtr(int iChannel) const = 0; 00605 00607 00608 virtual void* getDataPtr(int iChannel) = 0; 00609 00611 00612 00615 00616 00621 virtual void detach(int iIndex = -1)=0; 00622 00624 00632 virtual void removeChannel(int iChannel)=0; 00633 00635 00640 virtual void swapChannels(int iIndexA, int iIndexB)=0; 00641 00642 00644 void setParams(const ImgParams ¶ms); 00645 00647 00658 virtual void setChannels(int iNewNumChannels)=0; 00659 00661 00672 virtual void setSize(const utils::Size &s)=0; 00673 00675 00683 void setFormat(format fmt); 00684 00686 void setTime(const utils::Time time) { m_timestamp = time; } 00688 void setTime() { m_timestamp = utils::Time::now(); } 00689 00691 00695 00696 00700 icl64f getMax(int iChannel, utils::Point *coords=0) const; 00701 00703 00707 icl64f getMin(int iChannel, utils::Point *coords=0) const; 00708 00709 00711 icl64f getMin() const; 00712 00714 icl64f getMax() const; 00715 00717 00724 const utils::Range<icl64f> getMinMax(int iChannel, 00725 utils::Point *minCoords=0, 00726 utils::Point *maxCoords=0) const; 00727 00729 00731 const utils::Range<icl64f> getMinMax() const; 00732 00733 00735 00738 00739 00746 virtual void scale(const utils::Size& s, scalemode eScaleMode=interpolateNN)=0; 00747 00748 00750 00757 virtual void mirror(axis eAxis, bool bOnlyROI=false)=0; 00758 00760 00764 void clear(int iChannel = -1, icl64f val=0, bool bROIOnly=true); 00765 00767 00771 void normalizeAllChannels(const utils::Range<icl64f> &dstRange); 00772 00774 00778 void normalizeChannel(int iChannel,const utils::Range<icl64f> &srcRange, 00779 const utils::Range<icl64f> &dstRange); 00780 00781 00783 00789 void normalizeChannel(int iChannel, const utils::Range<icl64f> &dstRange); 00790 00792 00795 void normalizeImg(const utils::Range<icl64f> &srcRange, 00796 const utils::Range<icl64f> &dstRange); 00797 00799 00804 void normalizeImg(const utils::Range<icl64f> &dstRange); 00805 00807 00810 00811 00814 void print(const std::string sTitle="image") const; 00815 00817 bool validChannel(const int iChannel) const { 00818 return iChannel >= 0 && iChannel < getChannels(); 00819 } 00820 00822 00825 bool isEqual(const utils::Size &s, int nChannels) const { 00826 FUNCTION_LOG("isEqual("<<s.width<<","<< s.height << ","<< nChannels << ")"); 00827 return (getSize() == s) && (getChannels() == nChannels); 00828 } 00829 00831 bool isEqual(const ImgParams ¶ms){ 00832 FUNCTION_LOG(""); 00833 return m_oParams == params; 00834 } 00835 00837 bool isEqual(const ImgParams ¶ms, depth d){ 00838 FUNCTION_LOG(""); 00839 return m_oParams == params && getDepth() == d; 00840 } 00841 00843 bool isEqual(const ImgBase *otherImage){ 00844 FUNCTION_LOG(""); 00845 ICLASSERT_RETURN_VAL(otherImage,false); 00846 return getParams() == otherImage->getParams() && getDepth() == otherImage->getDepth(); 00847 } 00848 00850 00853 virtual bool isIndependent() const=0; 00855 00857 inline bool hasMetaData() const { return m_metaData.length(); } 00858 00860 inline void setMetaData(const std::string &data){ 00861 m_metaData = data; 00862 } 00863 00865 inline void clearMetaData(){ 00866 setMetaData(""); 00867 } 00868 00870 inline const std::string &getMetaData() const { 00871 return m_metaData; 00872 } 00873 00875 std::string &getMetaData() { 00876 return m_metaData; 00877 } 00878 00879 00880 protected: 00881 00883 ImgBase(depth d, const ImgParams& params); 00884 00886 00892 ImgParams m_oParams; 00893 00895 depth m_eDepth; 00896 00898 utils::Time m_timestamp; 00899 00901 std::string m_metaData; 00902 }; 00903 00905 ICLCore_API std::ostream &operator<<(std::ostream &s, const ImgBase &image); 00906 } // namespace core 00907 } 00908