#include #include namespace NICE { template ImageT

* addConstBorder(const ImageT

&src, uint width, uint height, P value, ImageT

* dst) { ImageT

* result = createResultBuffer(src.width()+2*width, src.height()+2*height, dst); #ifdef NICE_USELIB_IPP IppStatus ret = ippiCopyConstBorder_C1R(src.getPixelPointer(), src.getStepsize(), makeROIFullImage(src), result->getPixelPointer(), result->getStepsize(), makeROIFullImage(*result), height, width, value); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); #else // NICE_USELIB_IPP fthrow(ImageException,"Not yet supported without IPP."); #endif // NICE_USELIB_IPP return(result); } template ImageT

* copyBorder(const ImageT

&src, uint width, uint height, ImageT

* dst) { ImageT

* result = createResultBuffer(src.width(), src.height(), dst); if ( (2*(int)width > src.width()) || (2*(int)height > src.height()) ) fthrow(ImageException,"Border exceeds image size."); // inefficient version for ( int y = 0 ; y < (int)height ; y++ ) for ( int x = 0 ; x < src.width() ; x++ ) result->setPixel ( x, y, src.getPixel ( x, y ) ); for ( int y = src.height() - height ; y < src.height() ; y++ ) for ( int x = 0 ; x < src.width() ; x++ ) result->setPixel ( x, y, src.getPixel ( x, y ) ); for ( int x = 0 ; x < (int)width ; x++ ) for ( int y = (int)height ; y < src.height() - (int)height ; y++ ) result->setPixel ( x, y, src.getPixel ( x, y ) ); for ( int x = src.width()-width ; x < src.width() ; x++ ) for ( int y = (int)height ; y < src.height() - (int)height ; y++ ) result->setPixel ( x, y, src.getPixel ( x, y ) ); return result; } template void autoCropRect(const ImageT

&src, P color, Rect &rect) { bool quit=false; for(int y=0;ycolor) { rect.top=y; quit=true; break; } } if(quit) break; } quit=false; for(int y=src.height()-1;y>=0;y--) { for(int x=0;xcolor) { rect.height=y-rect.top+1; quit=true; break; } } if(quit) break; } quit=false; for(int x=0;xcolor) { rect.left=x; quit=true; break; } } if(quit) break; } quit=false; for(int x=src.width()-1;x>=0;x--) { for(int y=0;ycolor) { rect.width=x-rect.left+1; quit=true; break; } } if(quit) break; } } template void normalizeToRange(const ImageT

&src, ImageT

&dst , P min, P max) { ImageT

cpy=src; normalizeToRange(cpy,min,max); dst=cpy; } template void normalizeToRange(ImageT

&src, P min, P max) { //compute scale P src_max,src_min; src.minmax(src_min,src_max); if(src_max-src_min > static_cast

(1e-8)) { P scale=(max-min)/(src_max-src_min); for (int y=0;y void findLocalMinima(const ImageT

&src, P thresh, int dist, std::vector &minima) { ImageT

cpy=src; Coord minidx = cpy.minIndex(); P min = cpy(minidx); while(mindist)? minidx.y-dist : 0; int left = (minidx.x>dist)? minidx.x-dist : 0; int height = (minidx.y+dist simage = cpy.subImage(area); simage=std::numeric_limits

::max(); minidx = cpy.minIndex(); min = cpy(minidx); } } template void findLocalMaxima(const ImageT

&src, P thresh, int dist, std::vector &maxima) { ImageT

cpy=src; Coord maxidx = cpy.maxIndex(); P max = cpy(maxidx); while(max>thresh) { maxima.push_back(maxidx); int top = (maxidx.y>dist)? maxidx.y-dist : 0; int left = (maxidx.x>dist)? maxidx.x-dist : 0; int height = (maxidx.y+dist simage = cpy.subImage(area); simage=std::numeric_limits

::min(); maxidx = cpy.maxIndex(); max = cpy(maxidx); } } template IppiConnectedComp* floodFill4Connected(ImageT

& src, const IppiPoint& seed, const P& newVal, IppiConnectedComp* compBuffer) { if(compBuffer==NULL) compBuffer = new IppiConnectedComp; #ifdef NICE_USELIB_IPP IppiSize roiSize = {src.width(), src.height()}; Ipp32s buffSize; ippiFloodFillGetSize(roiSize, &buffSize); Ipp8u* floodBuffer = new Ipp8u[buffSize]; IppStatus ret = ippiFloodFill_4Con_C1IR(src.getPixelPointer(), src.getStepsize(), roiSize, seed, newVal, compBuffer, floodBuffer); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); // clean up delete floodBuffer; return compBuffer; #else fthrow(ImageException,"Not yet supportet without IPP."); #endif // NICE_USELIB_IPP return NULL; } template IppiConnectedComp* floodFill8Connected(ImageT

& src, const IppiPoint& seed, const P& newVal, IppiConnectedComp* compBuffer) { if(compBuffer==NULL) compBuffer = new IppiConnectedComp; #ifdef NICE_USELIB_IPP IppiSize roiSize = {src.width(), src.height()}; Ipp32s buffSize; ippiFloodFillGetSize(roiSize, &buffSize); Ipp8u* floodBuffer = new Ipp8u[buffSize]; IppStatus ret = ippiFloodFill_8Con_C1IR(src.getPixelPointer(), src.getStepsize(), roiSize, seed, newVal, compBuffer, floodBuffer); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); // clean up delete floodBuffer; return compBuffer; #else fthrow(ImageException,"Not yet supportet without IPP."); #endif // NICE_USELIB_IPP return NULL; } template void Floodfill(ImageT

& src, int startx, int starty, uint _newVal, uint _minDelta, uint _maxDelta) { #ifdef NICE_USELIB_IPP int pBufferSize; IppStatus ret = ippiFloodFillGetSize_Grad(makeROIFullImage(src), &pBufferSize); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); Ipp8u pBuffer[pBufferSize]; IppiPoint seed = {startx, starty}; IppiConnectedComp pRegion; ret = ippiFloodFill_Grad8Con_C1IR(src.getPixelPointer(), src.getStepsize(), makeROIFullImage(src), seed, static_cast(_newVal), static_cast(_minDelta), static_cast(_maxDelta), &pRegion, pBuffer); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); #else // NICE_USELIB_IPP fthrow(ImageException,"Not yet supportet without IPP."); #endif // NICE_USELIB_IPP } template void Floodfill(ColorImageT

& src, int startx, int starty, uint _newVal, uint _minDelta, uint _maxDelta) { FloodfillRGB(src,startx,starty,_newVal,_newVal,_newVal, _minDelta,_minDelta,_minDelta,_maxDelta,_maxDelta,_maxDelta); } template void FloodfillRGB(ColorImageT

& src, int startx, int starty, uint _newValR, uint _newValG, uint _newValB, uint _minDeltaR, uint _minDeltaG, uint _minDeltaB, uint _maxDeltaR, uint _maxDeltaG, uint _maxDeltaB) { #ifdef NICE_USELIB_IPP int pBufferSize; IppStatus ret = ippiFloodFillGetSize_Grad(makeROIFullImage(src), &pBufferSize); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); Ipp8u pBuffer[pBufferSize]; IppiPoint seed = {startx, starty}; IppiConnectedComp pRegion; Ipp8u newVal[3] = {_newValR,_newValG,_newValB}; Ipp8u minDelta[3] = {_minDeltaR,_minDeltaG,_minDeltaB}; Ipp8u maxDelta[3] = {_maxDeltaR,_maxDeltaG,_maxDeltaB}; ret = ippiFloodFill_Grad8Con_C3IR(src.getPixelPointer(), src.getStepsize(), makeROIFullImage(src), seed, newVal, minDelta, maxDelta, &pRegion, pBuffer); if(ret!=ippStsNoErr) fthrow(ImageException, ippGetStatusString(ret)); #else // NICE_USELIB_IPP fthrow(ImageException,"Not yet supportet without IPP."); #endif // NICE_USELIB_IPP } }