/* * compute the second and up iterations of a probability map * using the given aPriori probabilites per pixel. */ bool probabilityMap2D::computeMap(const channel8& src1, const channel8& src2, channel& aPrioriDest) const { point chnl1_size = src1.size(); point chnl2_size = src2.size(); // size of src1 equals src2 ? if ( (chnl1_size.x != chnl2_size.x) || (chnl1_size.y != chnl2_size.y) ) { setStatusString("probabilityMap2D: channels do not match"); return false; } else { int y; vector<channel8::value_type>::const_iterator srcIterator1, eit1; vector<channel8::value_type>::const_iterator srcIterator2, eit2; vector<channel::value_type>::iterator destIterator; const parameters& param = getParameters(); const thistogram<double>& objModel = param.getObjectColorModel(); const thistogram<double>& nonObjModel = param.getNonObjectColorModel(); float relObjProb; float relNonObjProb; ivector theBin(2); for (y=0;y<src1.rows();++y) { srcIterator1 = src1.getRow(y).begin(); eit1 = src1.getRow(y).end(); srcIterator2 = src2.getRow(y).begin(); eit2 = src2.getRow(y).end(); destIterator = aPrioriDest.getRow(y).begin(); while (srcIterator1 != eit1) { theBin[0] = lookupTable[0][*srcIterator1]; theBin[1] = lookupTable[1][*srcIterator2]; relObjProb = static_cast<float>(objModel.getProbability(theBin) * (*destIterator)); relNonObjProb = static_cast<float>(nonObjModel.getProbability(theBin)* (1.0f-(*destIterator))); // assume non-object if no entries are given if ((relObjProb == 0.0f) && (relNonObjProb == 0.0f)) { (*destIterator) = 0.0f; } else { // bayes (*destIterator) = relObjProb / (relObjProb + relNonObjProb); } srcIterator1++; srcIterator2++; destIterator++; } } } return true; }
// merge 8-bit channels bool mergeOCPToImage::apply(const channel8& c1, const channel8& c2, const channel8& c3, image& img) const { point p; // coordinates float r,g,b; // unnormed RGB channels float RG, BY, WB; // opponent colour channels if ((c1.size() != c2.size()) || (c1.size() != c3.size())) { setStatusString("sizes of channels do not match"); return false; } img.resize(c1.size(),rgbPixel(),false,false); for (p.y=0;p.y<img.rows();p.y++) { for (p.x=0;p.x<img.columns();p.x++) { RG = static_cast<float>(c1.at(p)) - 127.5f; BY = static_cast<float>(c2.at(p)) - 127.5f; WB = static_cast<float>(c3.at(p)) - 127.5f; b = BY*0.66666666666667f; // r = WB + RG - b; g = WB - RG - b; b = WB + BY*1.3333333333333f; // truncate r,g and b if the value is not in intervall [0..1] // can happen due to rounding errors in split operation if (r<0.0f) { r=0.0f; } else if (r>255.0f) { r=255.0f; } if (g<0.0f) { g=0.0f; } else if (g>255.0f) { g=255.0f; } if (b<0.0f) { b=0.0f; } else if (b>255.0f) { b=255.0f; } img.at(p).set(static_cast<ubyte>(r), static_cast<ubyte>(g), static_cast<ubyte>(b), 0); } } return true; };
// On copy apply for type channel8! bool harrisCorners::apply(const channel8& src,channel8& dest) const { pointList pts; if (apply(src,pts)) { const parameters& par = getParameters(); pointList::iterator it; dest.resize(src.size(),par.noCornerValue,false,true); for (it=pts.begin();it!=pts.end();++it) { dest.at(*it)=par.cornerValue; } return true; } return false; };
// return probability channel bool probabilityMap2D::apply(const channel8& src1, const channel8& src2, channel& dest) const { const parameters& param = getParameters(); point chnl1_size = src1.size(); point chnl2_size = src2.size(); // size of src1 equals src2 ? if ( (chnl1_size.x != chnl2_size.x) || (chnl1_size.y != chnl2_size.y) ) { setStatusString("probabilityMap2D: channels do not match"); return false; } // the color model MUST have 2 dimensions! if (probabilityHistogram.dimensions() == 2) { // resize probability channel dest.resize(src1.size()); ivector theBin(2); // compute first iteration int y; vector<channel8::value_type>::const_iterator srcIterator1, eit1; vector<channel8::value_type>::const_iterator srcIterator2, eit2; vector<channel::value_type>::iterator destIterator; for (y=0;y<src1.rows();++y) { srcIterator1 = src1.getRow(y).begin(); eit1 = src1.getRow(y).end(); srcIterator2 = src2.getRow(y).begin(); eit2 = src2.getRow(y).end(); destIterator = dest.getRow(y).begin(); while (srcIterator1 != eit1) { theBin[0] = lookupTable[0][*srcIterator1]; theBin[1] = lookupTable[1][*srcIterator2]; (*destIterator)=static_cast<float>(probabilityHistogram.at(theBin)); srcIterator1++; srcIterator2++; destIterator++; } } // compute all other iterations if (param.iterations > 1) { int i; if (param.gaussian) { gaussKernel2D<float> gk(param.windowSize,param.variance); convolution convolver; convolution::parameters convParam; convParam.boundaryType = lti::Mirror; convParam.setKernel(gk); convolver.setParameters(convParam); for (i=1;i<param.iterations;++i) { convolver.apply(dest); computeMap(src1,src2,dest); } } else { squareConvolution<float> convolver; squareConvolution<float>::parameters convParam; convParam.boundaryType = lti::Mirror; convParam.initSquare(param.windowSize); convolver.setParameters(convParam); for (i=1;i<param.iterations;++i) { convolver.apply(dest); computeMap(src1,src2,dest); } } } // of (param.iterations > 1) return true; } // of (probabilityHistogram.dimensions() == 2) setStatusString("probabilityMap2D: no models loaded"); return false; }