/******************************************************************** ** 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 : ICLFilter/src/MedianOp.cpp ** ** Module : ICLFilter ** ** Authors: Christof Elbrechter, Robert Haschke, Andre Justus ** ** ** ** ** ** 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 #include using namespace icl::utils; using namespace icl::core; namespace icl { namespace filter{ namespace{ template void apply_median (const Img *src, Img *dst, const Size &oMaskSize,const Point &roiOffset, const Point &oAnchor) { // {{{ open std::vector oList(oMaskSize.getDim()); typename std::vector::iterator itList = oList.begin(); typename std::vector::iterator itMedian = oList.begin()+((oMaskSize.width * oMaskSize.height)/2); for (int c=0;cgetChannels();c++){ const ImgIterator s(const_cast(src->getData(c)),src->getWidth(), Rect(roiOffset, dst->getROISize())); const ImgIterator sEnd = ImgIterator::create_end_roi_iterator(src->getData(c),src->getWidth(),Rect(roiOffset, dst->getROISize())); ImgIterator d= dst->beginROI(c); for(;s != sEnd;++s,++d){ for(const ImgIterator sR(s,oMaskSize,oAnchor); sR.inRegionSubROI(); ++sR, ++itList){ *itList = *sR; } std::sort(oList.begin(),oList.end()); *d = *itMedian; itList = oList.begin(); } } } // }}} #ifdef HAVE_IPP template void ippMedian(const Img* src, Img *dst, const Size& maskSize,const Point &roiOffset, const Point &oAnchor) { // {{{ open for(int c=0; c < src->getChannels(); c++) { ippiFunc(src->getROIData (c,roiOffset), src->getLineStep(), dst->getROIData (c), dst->getLineStep(), dst->getROISize(), maskSize, oAnchor); } } // }}} template void ippMedianFixed(const Img*src, Img *dst,const Point &roiOffset, int maskSize) { // {{{ open for(int c=0; c < src->getChannels(); c++) { ippiFunc(src->getROIData(c,roiOffset), src->getLineStep(), dst->getROIData(c), dst->getLineStep(), dst->getROISize(), maskSize == 3 ? ippMskSize3x3 : ippMskSize5x5); } } // }}} template<> void apply_median(const Img8u *src, Img8u *dst, const Size &maskSize,const Point &roiOffset, const Point &anchor){ // {{{ open if(maskSize == Size(3,3)){ ippMedianFixed(src,dst,roiOffset,3); }else if(maskSize == Size(5,5)){ ippMedianFixed(src,dst,roiOffset,5); }else{ ippMedian(src,dst,maskSize,roiOffset,anchor); } } // }}} template<> void apply_median(const Img16s *src, Img16s *dst, const Size &maskSize,const Point &roiOffset, const Point &anchor){ // {{{ open if(maskSize == Size(3,3)){ ippMedianFixed(src,dst,roiOffset,3); }else if(maskSize == Size(5,5)){ ippMedianFixed(src,dst,roiOffset,5); }else{ ippMedian(src,dst,maskSize,roiOffset,anchor); } } // }}} #endif } // end of anonymous namespace void MedianOp::apply(const ImgBase *poSrc, ImgBase **ppoDst){ // {{{ open FUNCTION_LOG(""); if (!prepare (ppoDst, poSrc)) return; switch(poSrc->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: \ apply_median(poSrc->asImg(), \ (*ppoDst)->asImg(), \ getMaskSize(), \ getROIOffset(), \ getAnchor()); \ break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} } // namespace filter }