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.GPL ** 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 <vector> 00035 #include <string> 00036 #include <ICLCore/CoreFunctions.h> 00037 #include <ICLCore/ImgParams.h> 00038 #include <ICLUtils/Time.h> 00039 #include <ICLUtils/Range.h> 00040 #include <ICLUtils/SmartPtr.h> 00041 00042 namespace icl { 00043 namespace core{ 00044 00046 00130 class ImgBase{ 00131 public: 00132 00134 virtual ~ImgBase(); 00135 00149 virtual ImgBase *shallowCopy(const utils::Rect &roi, 00150 const std::vector<int> &channelIndices, 00151 format fmt, 00152 utils::Time time=utils::Time::null, 00153 ImgBase **ppoDst = NULL) = 0; 00154 00167 const ImgBase *shallowCopy(const utils::Rect &roi, 00168 const std::vector<int> &channelIndices, 00169 format fmt, 00170 utils::Time time=utils::Time::null) const{ 00171 // casting constness away is safe, because we effectively return a const Img<Type>* 00172 return const_cast<ImgBase*>(this)->shallowCopy(roi,channelIndices,fmt,time,0); 00173 } 00174 00175 00177 00182 ImgBase *reinterpretChannels(format newFmt, ImgBase **ppoDst = NULL){ 00183 return shallowCopy(getROI(),std::vector<int>(),newFmt,getTime(),ppoDst); 00184 } 00185 00186 00188 00192 const ImgBase *reinterpretChannels(format newFmt) const{ 00193 // casting constness away is safe, because we effectively return a const Img<Type>* 00194 return const_cast<ImgBase*>(this)->shallowCopy(getROI(),std::vector<int>(),newFmt,getTime()); 00195 } 00197 00208 ImgBase* shallowCopy(const utils::Rect &roi, ImgBase** ppoDst = NULL){ 00209 return shallowCopy(roi,std::vector<int>(),getFormat(),getTime(),ppoDst); 00210 } 00211 ImgBase* shallowCopy(ImgBase** ppoDst = NULL){ 00212 return shallowCopy(getROI(),std::vector<int>(),getFormat(),getTime(),ppoDst); 00213 } 00214 00216 00225 const ImgBase* shallowCopy(const utils::Rect& roi) const { 00226 // casting constness away is safe, because we effectively return a const Img<Type>* 00227 return const_cast<ImgBase*>(this)->shallowCopy(roi,0); 00228 } 00229 00230 00232 00241 ImgBase* selectChannels (const std::vector<int>& channelIndices, ImgBase** ppoDst=0){ 00242 return shallowCopy(getROI(),channelIndices,formatMatrix,getTime(),ppoDst); 00243 } 00244 00246 00253 ImgBase* selectChannel(int channelIndex, ImgBase **ppoDst=0){ 00254 ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0); 00255 std::vector<int> v(1); v[0]= channelIndex; 00256 return selectChannels(v,ppoDst); 00257 } 00259 00262 const ImgBase* selectChannels (const std::vector<int>& channelIndices) const { 00263 // casting constness away is safe, because we effectively return a const Img<Type>* 00264 return const_cast<ImgBase*>(this)->selectChannels(channelIndices, 0); 00265 } 00266 00268 00274 const ImgBase *selectChannel(int channelIndex) const{ 00275 ICLASSERT_RETURN_VAL(validChannel(channelIndex), 0); 00276 std::vector<int> v(1); v[0]= channelIndex; return selectChannels(v); 00277 } 00278 00280 00281 00289 virtual ImgBase *deepCopy(ImgBase **ppoDst=0) const=0; 00290 00292 00301 virtual ImgBase *deepCopyROI(ImgBase **ppoDst=0) const=0; 00302 00304 00318 template<class T> 00319 Img<T> *convert(Img<T> *poDst=NULL) const; 00320 00322 00328 ImgBase *convert(depth d) const; 00329 00331 00334 ImgBase *convert(ImgBase *poDst) const; 00335 00337 00342 template<class T> 00343 Img<T> *convertROI(Img<T> *poDst=NULL) const; 00344 00346 00351 ImgBase *convertROI(depth d) const; 00352 00353 00355 00361 ImgBase *convertROI(ImgBase *poDst) const; 00362 00364 00368 virtual ImgBase *scaledCopy(const utils::Size &newSize, 00369 scalemode eScaleMode=interpolateNN) const = 0; 00370 00372 00380 virtual ImgBase *scaledCopy(ImgBase **ppoDst=0, 00381 scalemode eScaleMode=interpolateNN) const = 0; 00382 00384 00390 virtual ImgBase *scaledCopyROI(const utils::Size &newSize, 00391 scalemode eScaleMode=interpolateNN) const = 0; 00392 00394 00400 virtual ImgBase *scaledCopyROI(ImgBase **ppoDst=0, 00401 scalemode eScaleMode=interpolateNN) const = 0; 00402 00404 00406 00407 00415 template <class T> 00416 Img<T> *asImg() { 00417 ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == this->getDepth(), 0); 00418 return reinterpret_cast<Img<T>*>(this); 00419 } 00420 00422 00425 template <class T> 00426 const Img<T> *asImg() const { 00427 ICLASSERT_RETURN_VAL( icl::core::getDepth<T>() == getDepth(), 0); 00428 return reinterpret_cast<const Img<T>*>(this); 00429 } 00430 00432 inline Img<icl8u> *as8u() { return asImg<icl8u>(); } 00433 00435 inline Img<icl16s> *as16s() { return asImg<icl16s>(); } 00436 00438 inline Img<icl32s> *as32s() { return asImg<icl32s>(); } 00439 00441 inline Img<icl32f> *as32f() { return asImg<icl32f>(); } 00442 00444 inline Img<icl64f> *as64f() { return asImg<icl64f>(); } 00445 00446 00448 inline const Img<icl8u> *as8u() const { return asImg<icl8u>(); } 00449 00451 inline const Img<icl16s> *as16s() const { return asImg<icl16s>(); } 00452 00454 inline const Img<icl32s> *as32s() const { return asImg<icl32s>(); } 00455 00457 inline const Img<icl32f> *as32f() const { return asImg<icl32f>(); } 00458 00460 inline const Img<icl64f> *as64f() const { return asImg<icl64f>(); } 00461 00463 00466 00467 00472 const ImgParams &getParams() const{ return m_oParams; } 00474 00475 // returns the images size 00476 const utils::Size& getSize() const { return m_oParams.getSize(); } 00477 00479 int getWidth() const { return m_oParams.getWidth(); } 00480 00482 int getHeight() const { return m_oParams.getHeight(); } 00483 00485 int getDim() const { return m_oParams.getDim(); } 00486 00488 int getChannels() const { return m_oParams.getChannels(); } 00489 00491 depth getDepth() const { return m_eDepth; } 00492 00494 format getFormat() const { return m_oParams.getFormat(); } 00495 00497 utils::Time getTime() const { return m_timestamp; } 00498 00500 00502 virtual int getLineStep() const = 0; 00503 00504 00505 00507 00510 00511 const utils::Rect &getROI() const{ return m_oParams.getROI(); } 00512 00514 void getROI(utils::Point& offset, utils::Size& size) const { m_oParams.getROI(offset,size); } 00515 00517 utils::Point getROIOffset() const{ return m_oParams.getROIOffset(); } 00518 00520 utils::Size getROISize() const{ return m_oParams.getROISize(); } 00521 00523 int getROIWidth() const{ return m_oParams.getROIWidth(); } 00524 00526 int getROIHeight() const{ return m_oParams.getROIHeight(); } 00527 00529 int getROIXOffset() const{ return m_oParams.getROIXOffset(); } 00530 00532 int getROIYOffset() const{ return m_oParams.getROIYOffset(); } 00533 00535 utils::Rect getImageRect() const { return utils::Rect(utils::Point::null,getSize()); } 00536 00538 void setROIOffset(const utils::Point &offset) { m_oParams.setROIOffset(offset); } 00539 00541 void setROISize(const utils::Size &size) { m_oParams.setROISize(size); } 00542 00544 void setROI(const utils::Point &offset, const utils::Size &size){ m_oParams.setROI(offset,size); } 00545 00547 void setROI(const utils::Rect &roi) { m_oParams.setROI(roi); } 00548 00550 00551 void setROIOffsetAdaptive(const utils::Point &offset) { m_oParams.setROIOffsetAdaptive(offset); } 00552 00554 00555 void setROISizeAdaptive(const utils::Size &size){ m_oParams.setROISizeAdaptive(size); } 00556 00558 00559 void setROIAdaptive(const utils::Rect &roi) { m_oParams.setROIAdaptive(roi); } 00560 00562 int hasFullROI() const { return m_oParams.hasFullROI(); } 00563 00565 void setFullROI() { m_oParams.setFullROI(); } 00566 00568 00569 00572 00573 00577 virtual void fillBorder(bool setFullROI=true)=0; 00578 00580 virtual void fillBorder(icl64f val, bool setFullROI=true)=0; 00581 00583 00586 virtual void fillBorder(const std::vector<icl64f> &vals, bool setFullROI=true)=0; 00587 00588 00590 00594 virtual void fillBorder(const ImgBase *src, bool setFullROI=true)=0; 00595 00597 00601 00602 00603 virtual const void* getDataPtr(int iChannel) const = 0; 00604 00606 00607 virtual void* getDataPtr(int iChannel) = 0; 00608 00610 00611 00614 00615 00620 virtual void detach(int iIndex = -1)=0; 00621 00623 00631 virtual void removeChannel(int iChannel)=0; 00632 00634 00639 virtual void swapChannels(int iIndexA, int iIndexB)=0; 00640 00641 00643 void setParams(const ImgParams ¶ms); 00644 00646 00657 virtual void setChannels(int iNewNumChannels)=0; 00658 00660 00671 virtual void setSize(const utils::Size &s)=0; 00672 00674 00682 void setFormat(format fmt); 00683 00685 void setTime(const utils::Time time) { m_timestamp = time; } 00687 void setTime() { m_timestamp = utils::Time::now(); } 00688 00690 00694 00695 00699 icl64f getMax(int iChannel, utils::Point *coords=0) const; 00700 00702 00706 icl64f getMin(int iChannel, utils::Point *coords=0) const; 00707 00708 00710 icl64f getMin() const; 00711 00713 icl64f getMax() const; 00714 00716 00723 const utils::Range<icl64f> getMinMax(int iChannel, 00724 utils::Point *minCoords=0, 00725 utils::Point *maxCoords=0) const; 00726 00728 00730 const utils::Range<icl64f> getMinMax() const; 00731 00732 00734 00737 00738 00745 virtual void scale(const utils::Size& s, scalemode eScaleMode=interpolateNN)=0; 00746 00747 00749 00756 virtual void mirror(axis eAxis, bool bOnlyROI=false)=0; 00757 00759 00763 void clear(int iChannel = -1, icl64f val=0, bool bROIOnly=true); 00764 00766 00770 void normalizeAllChannels(const utils::Range<icl64f> &dstRange); 00771 00773 00777 void normalizeChannel(int iChannel,const utils::Range<icl64f> &srcRange, 00778 const utils::Range<icl64f> &dstRange); 00779 00780 00782 00788 void normalizeChannel(int iChannel, const utils::Range<icl64f> &dstRange); 00789 00791 00794 void normalizeImg(const utils::Range<icl64f> &srcRange, 00795 const utils::Range<icl64f> &dstRange); 00796 00798 00803 void normalizeImg(const utils::Range<icl64f> &dstRange); 00804 00806 00809 00810 00813 void print(const std::string sTitle="image") const; 00814 00816 bool validChannel(const int iChannel) const { 00817 return iChannel >= 0 && iChannel < getChannels(); 00818 } 00819 00821 00824 bool isEqual(const utils::Size &s, int nChannels) const { 00825 FUNCTION_LOG("isEqual("<<s.width<<","<< s.height << ","<< nChannels << ")"); 00826 return (getSize() == s) && (getChannels() == nChannels); 00827 } 00828 00830 bool isEqual(const ImgParams ¶ms){ 00831 FUNCTION_LOG(""); 00832 return m_oParams == params; 00833 } 00834 00836 bool isEqual(const ImgParams ¶ms, depth d){ 00837 FUNCTION_LOG(""); 00838 return m_oParams == params && getDepth() == d; 00839 } 00840 00842 bool isEqual(const ImgBase *otherImage){ 00843 FUNCTION_LOG(""); 00844 ICLASSERT_RETURN_VAL(otherImage,false); 00845 return getParams() == otherImage->getParams() && getDepth() == otherImage->getDepth(); 00846 } 00847 00849 00852 virtual bool isIndependent() const=0; 00854 00856 inline bool hasMetaData() const { return m_metaData.length(); } 00857 00859 inline void setMetaData(const std::string &data){ 00860 m_metaData = data; 00861 } 00862 00864 inline void clearMetaData(){ 00865 setMetaData(""); 00866 } 00867 00869 inline const std::string &getMetaData() const { 00870 return m_metaData; 00871 } 00872 00874 std::string &getMetaData() { 00875 return m_metaData; 00876 } 00877 00878 00879 protected: 00880 00882 ImgBase(depth d, const ImgParams& params); 00883 00885 00891 ImgParams m_oParams; 00892 00894 depth m_eDepth; 00895 00897 utils::Time m_timestamp; 00898 00900 std::string m_metaData; 00901 }; 00902 00904 std::ostream &operator<<(std::ostream &s, const ImgBase &image); 00905 } // namespace core 00906 } 00907