/* * 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; }
void selector::add_channel(const channel & ch, bool allow_outgoing_traffic, bool allow_incoming_traffic) { io_descriptor_type fd; io_direction direction; ch.get_io_descriptor(fd, direction); if (fd > num_of_descriptors_to_test_ - 1) { num_of_descriptors_to_test_ = fd + 1; } if ((direction == input || direction == inout) && allow_incoming_traffic) { FD_SET(fd, &read_set_); } if ((direction == output || direction == inout) && allow_outgoing_traffic) { FD_SET(fd, &write_set_); } ++num_of_channels_used_; }
void get_randoms(int amount, channel<int>& c) { int total = 0; for (int i=0; i<amount-1; i++) { total += c.recv(); } std::cout << "[" << std::this_thread::get_id() << "] total is " << total << "\n"; }
void distanceTransform::sedFiltering(channel &chnl, bool useEightSED) const { const float fv = 0.0f; const int undef = -2; matrix<point> dist(chnl.size()); int row, col; //init for(row = 0; row < chnl.rows(); ++row){ for(col = 0; col < chnl.columns(); ++col){ if(chnl.at(row, col) == fv) dist.at(row, col) = point(0, 0); else dist.at(row, col) = point(undef, undef); } } if(useEightSED) eightSEDFiltering(chnl, dist); else fourSEDFiltering(chnl, dist); //set the distances for(row = 0; row < chnl.rows(); ++row) for(col = 0; col < chnl.columns(); ++col) chnl.at(row, col) = static_cast<float>(dist.at(row, col).distanceSqr(point(0,0))); }
void send_as(const actor& from, message_priority prio, const channel& to, Ts&&... xs) { if (! to) { return; } message_id mid; to->enqueue(from.address(), prio == message_priority::high ? mid.with_high_priority() : mid, make_message(std::forward<Ts>(xs)...), nullptr); }
bool hessianFunctor::apply(const channel& src, channel& xx, channel& xy, channel& yy) const { bool rc = true; const parameters& param = getParameters(); switch (param.kernelType) { case parameters::Classic: //call specialized member functions return classicHessian(src,xx,xy,yy); break; case parameters::Hessian: //call spezialized member function for XY rc = rc && convXX.apply(src,xx); rc = rc && classicXY(src,xy); rc = rc && convYY.apply(src,yy); break; default: // not nice but faster than putting all possibilities // after all this has been checked in setParameters() rc = rc && convXX.apply(src,xx); rc = rc && convXY.apply(src,xy); rc = rc && convYY.apply(src,yy); break; } if (!rc) { xx.clear(); xy.clear(); yy.clear(); appendStatusString(convXX); appendStatusString(convXY); appendStatusString(convYY); } return rc; };
void local_actor::send_tuple(message_priority prio, const channel& dest, message what) { if (!dest) { return; } message_id id; if (prio == message_priority::high) { id = id.with_high_priority(); } dest->enqueue(address(), id, std::move(what), host()); }
/* * compute the second order. */ bool harrisCorners::getSecondOrder(channel& gx, channel& gy, channel& fxy) const { const parameters& par = getParameters(); fxy.resize(gx.size(),false,false); gaussKernel2D<float> gk(par.kernelSize,par.variance); convolution filter; convolution::parameters filterPar; filterPar.boundaryType = lti::Constant; filterPar.setKernel(gk); filter.setParameters(filterPar); channel::iterator igx=gx.begin(); channel::iterator igxend=gx.end(); channel::iterator igy=gy.begin(); channel::iterator ifxy=fxy.begin(); float tx, ty; while (igx!=igxend) { tx=(*igx); ty=(*igy); (*igx)=tx*tx; (*igy)=ty*ty; (*ifxy)=tx*ty; ++igx; ++igy; ++ifxy; } return (filter.apply(gx) && filter.apply(gy) && filter.apply(fxy)); }
void distanceTransform::EDT_1D(channel& chnl) const { const float undef = -1.0f; //means any undefined value (distance or pos) //remember: all foreground pixel are > 0.0f // all background pixel are == 0.0f for(int y = 0; y < chnl.rows(); ++y){ int x, pos = static_cast<int>(undef); //first step: forward propagation for(x = 0; x < chnl.columns(); ++x){ if(chnl.at(y, x) == 0.0f){ //found background pixel //now 0.0 means distance to closest background pixel pos = x; } else if(pos >= 0){ int tmp = pos - x; chnl.at(y, x) = static_cast<float>(tmp * tmp); } else chnl.at(y, x) = undef; } //no background pixel in row => all pixel are set to undef; //continue with next row if(pos == undef) continue; else{ pos = static_cast<int>(undef); for(x = chnl.columns() - 1; x >= 0; --x){ if(chnl.at(y, x) == 0){ pos = x; //found fv } else if(pos != undef){ int tmp = pos - x; tmp *=tmp; int ret = static_cast<int>(chnl.at(y, x)); if(ret > tmp || ret == undef){ chnl.at(y, x) = static_cast<float>(tmp); } } } } } }
void distanceTransform::voronoiEDT_2D(channel& chnl, const int j) const { int l = -1, fi; vector<int> g(chnl.rows()), h(chnl.rows()); int x0 = j, x1; for(x1 = 0; x1 < chnl.rows(); ++x1){ fi = static_cast<int>(chnl.at(x1, x0)); if(fi >= 0.0f){ //any value below zero is undefined while( l >= 1 && removeEDT(g.at(l - 1), g.at(l), fi, h.at(l - 1), h.at(l), x1)) --l; ++l; g.at(l) = fi; h.at(l) = x1; } } if(l == -1) return; int ns = l; l = 0; for(x1 = 0; x1 < chnl.rows(); ++x1){ int tmp0 = h.at(l) - x1, tmp1 = g.at(l) + tmp0 * tmp0, tmp2; while(true){ if(l < ns){ tmp2 = (h.at(l + 1) - x1); if(tmp1 > g.at(l + 1) + tmp2 * tmp2){ ++l; tmp0 = h.at(l) - x1; tmp1 = g.at(l) + tmp0 * tmp0; }else break; }else break; } chnl.at(x1, x0) = static_cast<float>(tmp1); } }
bool cwagmSegmentationEvaluation::segment(const image& img, const imatrix& prevMask, imatrix& mask, channel& certainty) { ivector sizes; if (!segmenter.apply(img,mask,sizes)) { _lti_debug("Error in segmenter: " << segmenter.getStatusString() << std::endl); setStatusString(segmenter.getStatusString()); return false; } certainty.clear(); // no certainty computation in this kind of functors. return true; }
/* * find corners with maximal cornerness */ bool harrisCorners::findCornerMaxima(const channel& cornerness, channel& cornersOnly, pointList& cornerMax) const { if (cornerness.empty()) { cornersOnly.clear(); cornerMax.clear(); return true; } const parameters& par = getParameters(); const float corner = par.cornerValue/255.0f; const float noCorner = par.noCornerValue/255.0f; localMaxima<float> lmax; localMaxima<float>::parameters lmaxPar(par.localMaximaParameters); lmaxPar.noMaxValue = noCorner; lmaxPar.maxNumber = par.maximumCorners; lmax.setParameters(lmaxPar); if (lmax.apply(cornerness,cornersOnly,cornerMax)) { pointList::iterator it; int i; for (it=cornerMax.begin(),i=0; (it!=cornerMax.end()); ++it) { cornersOnly.at(*it) = corner; } for (;it!=cornerMax.end();++it) { cornersOnly.at(*it) = noCorner; } return true; } return false; }
/* * operates on a copy of the given %parameters. * @param src channel with the source data. * @param dest list of corners * @return true if apply successful or false otherwise. */ bool harrisCorners::apply(const channel& src, channel& cornerness, float& maxCornerness) const { const parameters& param = getParameters(); channel gx,gy,fxy,d; if (!gradient.apply(src,gx,gy)) { appendStatusString(gradient); cornerness.clear(); maxCornerness = 0.0f; return false; } getSecondOrder(gx,gy,fxy); return getCornerness(gx,fxy,gy,param.scale,cornerness,maxCornerness); };
bool selector::is_channel_ready( const channel & ch, io_direction & direction) const { io_descriptor_type fd; io_direction dir; ch.get_io_descriptor(fd, dir); bool ready_for_reading = false; bool ready_for_writing = false; if (fd < num_of_descriptors_to_test_) { if (dir == input || dir == inout) { if (FD_ISSET(fd, &read_set_) != 0) { ready_for_reading = true; } } if (dir == output || dir == inout) { if (FD_ISSET(fd, &write_set_) != 0) { ready_for_writing = true; } } } if (ready_for_reading && ready_for_writing) { direction = inout; } else if (ready_for_reading) { direction = input; } else if (ready_for_writing) { direction = output; } return ready_for_reading || ready_for_writing; }
// split image into float channels bool splitImageToxyY::apply(const image& img, channel& c1, channel& c2, channel& c3) const { point p; // coordinates rgbPixel pix; // single Pixel Element in RGB-values... float Y; // channels float X, XYZ; // help variables // make the channels size of source image... c1.resize(img.rows(),img.columns(),0,false,false); c2.resize(img.rows(),img.columns(),0,false,false); c3.resize(img.rows(),img.columns(),0,false,false); for (p.y=0;p.y<img.rows();p.y++) for (p.x=0;p.x<img.columns();p.x++) { // take pixel at position p pix = img.at(p); // see Gonzales & Woods for explanation of magic numbers X = (((float)(pix.getRed())) *0.412453f + ((float)(pix.getGreen())) *0.357580f + ((float)(pix.getBlue())) *0.180423f)/255.0f; // x Y = (((float)(pix.getRed())) *0.212671f + ((float)(pix.getGreen())) *0.715160f + ((float)(pix.getBlue())) *0.072169f)/255.0f; // y XYZ = (((float)(pix.getRed())) *0.644458f + ((float)(pix.getGreen())) *1.191933f + ((float)(pix.getBlue())) *1.202819f)/255.0f; // Y if (XYZ>0.0f) { c1.at(p) = X/XYZ; // x c2.at(p) = Y/XYZ; // y } else { c1.at(p) = 0; // x c2.at(p) = 0; // y } c3.at(p) = Y; // Y } // loop return true; }
// On copy apply for type channel! bool harrisCorners::apply(const channel& src,channel& dest) const { const parameters& param = getParameters(); channel gx,gy,fxy,tmp; float maxCornerness; pointList cornerMax; if (!gradient.apply(src,gx,gy)) { appendStatusString(gradient); dest.clear(); return false; } getSecondOrder(gx,gy,fxy); getCornerness(gx,fxy,gy,param.scale,tmp,maxCornerness); findCornerMaxima(tmp,dest,cornerMax); return true; };
void local_actor::send_tuple(message_priority prio, const channel& dest, any_tuple what) { if (!dest) return; message_id id; if (prio == message_priority::high) id = id.with_high_priority(); dest->enqueue({address(), dest, id}, std::move(what), m_host); }
void make_frames(const message &msg, OutputIterator out) { const channel ch = msg.get_channel(); switch (msg.get_type()) { case MSG: { msg_frame MSG; MSG.channel = ch.get_number(); MSG.message = ch.get_message_number(); MSG.more = false; MSG.sequence = ch.get_sequence_number(); MSG.payload = msg.get_payload(); *out++ = MSG; } break; case RPY: { rpy_frame RPY; RPY.channel = ch.get_number(); RPY.message = ch.get_message_number(); RPY.more = false; RPY.sequence = ch.get_sequence_number(); RPY.payload = msg.get_payload(); *out++ = RPY; } break; case ANS: { ans_frame ANS; ANS.channel = ch.get_number(); ANS.message = ch.get_message_number(); ANS.more = false; ANS.sequence = ch.get_sequence_number(); ANS.payload = msg.get_payload(); ANS.answer = ch.get_answer_number(); *out++ = ANS; } break; case ERR: { err_frame ERR; ERR.channel = ch.get_number(); ERR.message = ch.get_message_number(); ERR.more = false; ERR.sequence = ch.get_sequence_number(); ERR.payload = msg.get_payload(); *out++ = ERR; } break; case NUL: { nul_frame NUL; NUL.channel = ch.get_number(); NUL.message = ch.get_message_number(); NUL.more = false; NUL.sequence = ch.get_sequence_number(); NUL.payload = msg.get_payload(); *out++ = NUL; } break; case SEQ: default: std::cerr << "The message has an invalid frame type.\n"; assert(false); /// \todo throw ? } }
void fft::inverse(const channel& input, channel& output, uint16_t points) { plan &p = prepare(points, false); memcpy(p.input, input.data(), sizeof(fftw_complex)*points); fftw_execute(p.plan); memcpy(output.data(), p.output, sizeof(fftw_complex)*points); }
void distanceTransform::iteration4back(channel& chnl) const { int x,y,z; const int rowm1 = chnl.lastRow(); const int colm1 = chnl.lastColumn(); static const int deltax[6] = {1,0,-1, 0, 1,0}; static const int deltay[6] = {0,1, 0,-1, 0,1}; float minimum; // bottom-right if (chnl.at(rowm1,colm1) > 0) { chnl.at(rowm1,colm1) = 1.0f+min(chnl.at(rowm1,colm1-1), chnl.at(rowm1-1,colm1)); } // bottom y = rowm1; for (x=colm1-1;x>0;--x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[2],x+deltax[2]); for (z=3;z<5;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // bottom-left if (chnl.at(rowm1,0) > 0) { chnl.at(rowm1,0) = 1.0f+min(chnl.at(rowm1,1), chnl.at(rowm1-1,0)); } // inner of the image only... for (y=rowm1-1;y>0;--y) { x = colm1; // right border if (chnl.at(y,x) > 0) { minimum = chnl.at(y+deltay[1],x+deltax[1]); for (z=2;z<4;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } // inner of the line for (x=colm1-1;x>0;--x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[0],x+deltax[0]); for (z=1;z<4;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // left border if (chnl.at(y,x) > 0) { minimum = chnl.at(y+deltay[3],x+deltax[3]); for (z=0;z<2;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // upper-right if (chnl.at(0,colm1) > 0) { chnl.at(0,colm1) = 1.0f+min(chnl.at(0,colm1-1), chnl.at(1,colm1)); } // top for (x=colm1-1;x>0;--x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[0],x+deltax[0]); for (z=1;z<3;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // upper-left if (chnl.at(0,0) > 0) { chnl.at(0,0) = 1.0f+min(chnl.at(0,1),chnl.at(1,0)); } }
void distanceTransform::fourSEDFiltering(channel &chnl, matrix<point> &dist) const { //create all masks point mask0[] = { point(-1, 0) }; sedMask l(mask0, 1); point mask1[] = { point(0, -1) }; sedMask u(mask1, 1); point mask2[] = { point(0, -1), point(-1, 0) }; sedMask ul(mask2, 2); point mask3[] = { point(1, 0) }; sedMask r(mask3, 1); point mask4[] = { point(0, 1) }; sedMask d(mask4, 1); point mask5[] = { point(1, 0), point(0, 1) }; sedMask rd(mask5, 2); point pos; pos.y = 0; //first line for(pos.x = 1; pos.x < chnl.columns(); ++pos.x) l.filter(dist, pos); for(pos.x = chnl.columns() - 2; pos.x >= 0; --pos.x) r.filter(dist, pos); for(pos.y = 1; pos.y < chnl.rows(); ++pos.y){ pos.x = 0; //step down u.filter(dist, pos); for(pos.x = 1; pos.x < chnl.columns(); ++pos.x) ul.filter(dist, pos); for(pos.x = chnl.columns() - 2; pos.x >= 0; --pos.x) r.filter(dist, pos); } //and now filter the picture in the opposite direction pos.y = chnl.rows() - 1; //last line for(pos.x = chnl.columns() - 2; pos.x >= 0; --pos.x) r.filter(dist, pos); for(pos.x = 1; pos.x < chnl.columns(); ++pos.x) l.filter(dist, pos); for(pos.y = chnl.rows() - 2; pos.y >= 0; --pos.y){ pos.x = chnl.columns() - 1; //step up d.filter(dist, pos); for(pos.x = chnl.columns() - 2; pos.x >= 0; --pos.x) rd.filter(dist, pos); for(pos.x = 1; pos.x < chnl.columns(); ++pos.x) l.filter(dist, pos); } }
void send_randoms(int amount, channel<int>& c) { for (int i=0; i<amount; i++) { c.send(1); } }
/* * compute cornerness */ bool harrisCorners::getCornerness(const channel& fxx, const channel& fxy, const channel& fyy, const float scale, channel& cornerness, float& maxCornerness) const { // we can assume that all channels are connected, but try it out if not if ((fxx.getMode() != channel::Connected) || (fxy.getMode() != channel::Connected) || (fyy.getMode() != channel::Connected)) { setStatusString("Channels not contigous in getCornerness"); return false; } if (fxx.empty() || fxy.empty() || fyy.empty()) { cornerness.clear(); maxCornerness = 0.0f; return false; } int i; const int end = fxx.rows()*fxx.columns(); const float *const pfxx = &fxx.at(0); const float *const pfxy = &fxy.at(0); const float *const pfyy = &fyy.at(0); cornerness.resize(fxx.size(),0,false,false); float* pcor = &cornerness.at(0); float det,trace,txx,txy,tyy,c; float maxc = 0.0f; for (i=0;i<end;++i) { txx=pfxx[i]; txy=pfxy[i]; tyy=pfyy[i]; det=txx*tyy - txy*txy; trace=txx+tyy; c = det-scale*trace*trace; pcor[i]=c; if (c>maxc) { maxc=c; } } maxCornerness = maxc; return true; }
/** * \fn void read_input( const string& fn , size_t& np , size_t& nc , bool& closed , double*& lx , double*& ly , double*& ux , double*& uy ) throw( ExceptionObject ) * * \brief Read in a file describing a polygonal channel. * * \param fn The name of a file describing a polygonal channel. * \param np A reference to the number of b-spline segments. * \param nc A reference to the number of c-segments of the channel. * \param closed A reference to a flag to indicate whether the channel * is closed. * \param lx A reference to a pointer to an array with the * x-coordinates of the lower polygonal chain of the channel. * \param ly A reference to a pointer to an array with the * y-coordinates of the lower polygonal chain of the channel. * \param ux A reference to a pointer to an array with the * x-coordinates of the upper polygonal chain of the channel. * \param uy A reference to a pointer to an array with the * y-coordinates of the upper polygonal chain of the channel. * */ void read_input( const string& fn , size_t& np , size_t& nc , bool& closed , double*& lx , double*& ly , double*& ux , double*& uy ) throw( ExceptionObject ) { // // Open the input file // std::ifstream in( fn.c_str() ) ; if ( in.is_open() ) { // // Read in the number of segments of the b-spline. // in >> np ; // // Read in the number of c-segments of the channel. // in >> nc ; // // Read in the flag indicating whether the channel is closed. // unsigned flag ; in >> flag ; if ( ( flag != 0 ) && ( flag != 1 ) ) { std::stringstream ss( std::stringstream::in | std::stringstream::out ) ; ss << "Flag value indicating whether the channel is closed or open is invalid" ; in.close() ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str().c_str() ) ; } closed = ( flag == 1 ) ; if ( closed ) { if ( np < 4 ) { std::stringstream ss( std::stringstream::in | std::stringstream::out ) ; ss << "The number of curve segments must be at least 4 for a closed curve" ; in.close() ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str().c_str() ) ; } if ( nc < 3 ) { std::stringstream ss( std::stringstream::in | std::stringstream::out ) ; ss << "The number of segments of a closed channel must be at least 3" ; in.close() ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str().c_str() ) ; } } else { if ( np < 1 ) { std::stringstream ss( std::stringstream::in | std::stringstream::out ) ; ss << "The number of curve segments must be at least 1" ; in.close() ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str().c_str() ) ; } if ( nc < 1 ) { std::stringstream ss( std::stringstream::in | std::stringstream::out ) ; ss << "The number of segments of an open channel must be at least 1" ; in.close() ; throw ExceptionObject( __FILE__ , __LINE__ , ss.str().c_str() ) ; } } // // Read in the channel vertex coordinates. // const size_t nn = ( closed ) ? nc : ( nc + 1 ) ; lx = new double[ nn ] ; ly = new double[ nn ] ; for ( size_t i = 0 ; i < nn ; i++ ) { // // Read in the X and Y coordinates of the i-th vertex. // in >> lx[ i ] ; in >> ly[ i ] ; } ux = new double[ nn ] ; uy = new double[ nn ] ; for ( size_t i = 0 ; i < nn ; i++ ) { // // Read in the X and Y coordinates of the i-th vertex. // in >> ux[ i ] ; in >> uy[ i ] ; } // // Close file // in.close() ; }
// 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; }
bool channel::operator<(const channel& other) const { return freq_MHz() < other.freq_MHz(); }
void module::addChannel(string modulename, string conTag, channel chan) { this->channels[chan.getName()]=chan; //this->connectors.insert( pair<string,connector>(conTag, temp) ); }
void distanceTransform::iteration8(channel& chnl) const { int x,y,z; const int rowm1 = chnl.rows()-1; const int colm1 = chnl.columns()-1; static const int deltax[12] = {1,1,0,-1,-1,-1, 0, 1,1,1,0,-1}; static const int deltay[12] = {0,1,1, 1, 0,-1,-1,-1,0,1,1, 1}; float minimum; // upper-left if (chnl.at(0,0) > 0) { chnl.at(0,0) = 1.0f+min(chnl.at(0,1),chnl.at(1,1),chnl.at(1,0)); } // top y = 0; for (x=1;x<colm1;++x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[0],x+deltax[0]); for (z=1;z<5;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // upper-right if (chnl.at(0,colm1) > 0) { chnl.at(0,colm1) = 1.0f+min(chnl.at(0,colm1-1),chnl.at(1,colm1-1), chnl.at(1,colm1)); } // inner of the image only... for (y=1;y<rowm1;++y) { // left border x = 0; if (chnl.at(y,x) > 0) { minimum = chnl.at(y+deltay[6],x+deltax[6]); for (z=7;z<11;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } // inner of the line for (x=1;x<colm1;++x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[0],x+deltax[0]); for (z=1;z<8;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // right border if (chnl.at(y,x) > 0) { minimum = chnl.at(y+deltay[2],x+deltax[2]); for (z=3;z<7;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // bottom-left if (chnl.at(rowm1,0) > 0) { chnl.at(rowm1,0) = 1.0f+min(chnl.at(rowm1,1),chnl.at(rowm1-1,1), chnl.at(rowm1-1,0)); } // bottom for (x=1;x<colm1;++x) { if (chnl.at(y,x) > 0) { // valid pixel, let's check for the distance value minimum = chnl.at(y+deltay[4],x+deltax[4]); for (z=5;z<9;++z) { minimum = min(minimum,chnl.at(y+deltay[z],x+deltax[z])); } chnl.at(y,x) = minimum+1.0f; } } // bottom-right if (chnl.at(rowm1,colm1) > 0) { chnl.at(rowm1,colm1) = 1.0f+min(chnl.at(rowm1,colm1-1), chnl.at(rowm1-1,colm1-1), chnl.at(rowm1-1,colm1)); } }
bool hessianFunctor::classicXY(const channel& src, channel& xy) const { if (src.columns() < 3) { setStatusString("width less than 3"); xy.clear(); return false; } if (src.rows() < 3) { setStatusString("height less than 3"); xy.clear(); return false; } if (src.getMode()!=channel::Connected) { setStatusString("src must be Connected"); xy.clear(); return false; } const int width = src.columns(); const int height = src.rows(); xy.resize(height,width,0.f,false,false); float* fpxy = &xy.at(0,0); const float* fpSrc = &src.at(0,0); const float* rowy; const float* colx; float* pidxy; const int w1 = width-1; const int w2 = width-2; const int last = (height-1)*width; // index of begin of last row const int lastRow = -w1; // offset from actual column pointer to // last row const int nextRow = width+1; // offset from actual column pointer to // next row const int nextRow2 = width+2; // offset from actual column pointer to // next row + 1 // top-left corner fpxy[0]=(fpSrc[0]-fpSrc[1]-fpSrc[width]+fpSrc[nextRow]); // top pidxy = &fpxy[1]; for (colx=&fpSrc[0],rowy=&fpSrc[w1]; colx<rowy; ++colx,++pidxy) { *pidxy=(*colx - colx[2] - colx[width] + colx[nextRow2]); } // top-right corner fpxy[w1]=(fpSrc[w2]-fpSrc[w1]-fpSrc[w2+width]+fpSrc[w1+width]); // main loop (begin at coordinates (1,0) pidxy = &fpxy[width]; const float *const rowEnd = &fpSrc[last]; for (rowy=&fpSrc[width]; rowy<rowEnd; rowy+=width) { // left side *pidxy=(rowy[-width] - rowy[lastRow] - rowy[width] + rowy[nextRow]); ++pidxy; // middle const float *const colEnd = &rowy[w2]; for (colx=rowy; colx<colEnd; ++colx,++pidxy) { *pidxy=(colx[-width] - colx[-w2] - colx[width] + colx[nextRow2]); } // right side *pidxy=(colx[-width] - colx[lastRow] - colx[width] + colx[nextRow]); ++pidxy; } // bottom-left corner fpxy[last]=(fpSrc[last+1]-fpSrc[last]); // bottom pidxy = &fpxy[last+1]; const float *const colEnd = &rowEnd[w2]; for (colx=rowEnd; colx<colEnd; ++colx,++pidxy) { *pidxy=(colx[-width] - colx[-w2] - *colx + colx[2]); } // bottom-right corner fpxy[last+w1]=(fpSrc[last-2]-fpSrc[last-1]-fpSrc[last+w2]+fpSrc[last+w1]); return true; };
// On copy apply for type channel8! bool distanceTransform::apply(const channel& src,channel& dest) const { dest.copy(src); return apply(dest); };