void processImageSobel(LPFImage output, LPFImage dx, LPFImage dy) { FImage tmpMags; newFImage(&tmpMags, dx->width, dx->height); FImage magnitudes; computeSuppressed(dx, dy, &tmpMags, &magnitudes); normaliseFImage(&magnitudes); float low = lowThresh; float high = highThresh; if (high < 0) { // if high has not been set we use a similar approach to matlab to // estimate the thresholds high = computeHighThreshold(&tmpMags); low = threshRatio * high; } // printf("low= %e, high= %e\n",low, high); // fflush(stdout); freeFImage(&tmpMags); thresholdingTracker(&magnitudes, output, low, high); freeFImage(&magnitudes); }
void RegionGrowingHSV::computeInitalSeed(std::vector<int> &seed) { int size_of_hist = static_cast<int>(360/hist_width)+1; std::vector< std::vector<int> > hist( size_of_hist ); std::pair<int,int> qujian; color_threshold_.resize(size_of_hist,qujian); // 统计分布到hist中 for(int i=0;i<cloud_hsv_.size();i++) { int index = static_cast<int>(cloud_hsv_[i]/hist_width); // index 可能小于0->h为-1 hist[index].push_back(i); } // 计算相对变化率 std::cout<<" calculate xdbhl_ "<<std::endl; xdbhl_.clear(); for(int i=0;i<hist.size()-1;i++) { float xd = std::abs(static_cast<float>(hist[i].size())-static_cast<float>(hist[i+1].size())); float fm = std::max(10.0f,(static_cast<float>(hist[i].size())+static_cast<float>(hist[i+1].size()))/2.0f); xdbhl_.push_back(static_cast<float>(xd/fm)); } // calculate color_threshold_; std::cout<<" calculate color_threshold_ "<<std::endl; for(int i=0;i<hist.size();i++) { qujian.first = computeLowThreshold(i,hist)-1; qujian.second = computeHighThreshold(i,hist)+1; color_threshold_[i] = qujian; //std::cout<<"the "<<i<<" color_threshold "<<color_threshold_[i].first<<" "<<color_threshold_[i].second<<"size "<<hist[i].size()<<std::endl; } // 计算优先级 std::cout<<" calculate hist_proi_ "<<std::endl; hist_proi_.clear(); for(int i=0;i<hist.size();i++) { float g = 0.0; if( i==0 ) { g = std::pow( xdbhl_[i],2.0f ); } else if( i==hist.size()-1 ) { g = std::pow( xdbhl_[i-1],2.0f ); } else g = std::pow( xdbhl_[i-1],2.0f ) + std::pow( xdbhl_[i],2.0f); this->hist_proi_.push_back(g); } // 计算点的优先级 std::cout<<"calculatePointPossibility!!!"<<std::endl; calculatePointPossibility(); point_proi_.clear(); for(int i=0;i<hist_proi_.size();i++) { std::pair<int,float> g; float hist_poss = static_cast<float>(hist[i].size())/static_cast<float>(num_pts); for(int j=0;j<hist[i].size();j++) { int point_id = hist[i][j]; g.first = point_id; g.second = possibility_[point_id] * hist_poss * (3.0f-hist_proi_[i]); point_proi_.push_back(g); } } // insert point id to the seed vector std::sort(point_proi_.begin(),point_proi_.end(),com); for(int i=0;i<point_proi_.size();i++) { seed.push_back(point_proi_[i].first); } }