00001 #include "MultiScaleDetector.h" 00002 00003 00004 MultiScaleDetector::MultiScaleDetector(const PeakFinder* _peak, unsigned int _scales, double _sigma, double step, SmoothingFilterFamily _filterType): 00005 m_peakFinder(_peak), 00006 m_scaleNumber(_scales), 00007 m_baseSigma(_sigma), 00008 m_sigmaStep(step), 00009 m_useMaxRange(false), 00010 m_filterType(_filterType) 00011 { 00012 computeFilterBank(); 00013 } 00014 00015 unsigned int MultiScaleDetector::detect(const LaserReading& reading, std::vector<InterestPoint*>& point) const{ 00016 std::vector<double> signal; 00017 std::vector< std::vector<double> > signalSmooth; 00018 std::vector< std::vector<double> > signalDiff; 00019 std::vector< std::vector<unsigned int> > indexes; 00020 return detect(reading, point, signal, signalSmooth, signalDiff, indexes); 00021 } 00022 00023 unsigned int MultiScaleDetector::detect(const LaserReading& reading, std::vector<InterestPoint*>& point, 00024 std::vector< double >& signal, 00025 std::vector< std::vector<double> >& signalSmooth, 00026 std::vector< std::vector<double> >& signalDiff, 00027 std::vector< std::vector<unsigned int> >& indexes) const 00028 { 00029 std::vector<unsigned int> maxRangeMapping; 00030 computeSignal(reading, signal, maxRangeMapping); 00031 detect(signal, signalSmooth, signalDiff, indexes); 00032 return computeInterestPoints(reading, signal, point, indexes, maxRangeMapping); 00033 } 00034 00035 void MultiScaleDetector::detect(const std::vector<double>& signal, 00036 std::vector< std::vector<double> >& signalSmooth, 00037 std::vector< std::vector<double> >& signalDiff, 00038 std::vector< std::vector<unsigned int> >& indexes) const 00039 { 00040 signalSmooth.resize(m_scaleNumber); 00041 signalDiff.resize(m_scaleNumber); 00042 indexes.resize(m_scaleNumber); 00043 for(unsigned int i = 0; i < m_filterBank.size(); i++){ 00044 int offsetRange = floor((int)m_filterBank[i].size()/2.0); 00045 signalSmooth[i] = convolve1D(signal, m_filterBank[i], -offsetRange); 00046 signalDiff[i] = convolve1D(signalSmooth[i], m_differentialBank[i], -1); 00047 for(unsigned int j = offsetRange + 1; j < signal.size() - offsetRange - 1; j++){ 00048 if(m_peakFinder->isPeak(signalDiff[i], j)){ 00049 indexes[i].push_back(j); 00050 } 00051 } 00052 } 00053 } 00054 00055 void MultiScaleDetector::computeFilterBank(){ 00056 m_filterBank.resize(m_scaleNumber); 00057 m_scales.resize(m_scaleNumber); 00058 for(unsigned int i = 0; i < m_filterBank.size(); i++){ 00059 m_scales[i] = m_baseSigma * pow(m_sigmaStep, i); 00060 unsigned int kernelSize = 2*ceil(m_scales[i])+1; 00061 if(kernelSize < MIN_KERNEL_SIZE) 00062 kernelSize = MIN_KERNEL_SIZE; 00063 else if(kernelSize > MAX_KERNEL_SIZE) 00064 kernelSize = MAX_KERNEL_SIZE; 00065 switch(m_filterType){ 00066 case GAUSSIAN: 00067 m_filterBank[i] = gaussianKernel1D(m_scales[i], kernelSize); break; 00068 case BESSEL: 00069 m_filterBank[i] = besselKernel1D(m_scales[i], kernelSize); break; 00070 default: 00071 m_filterBank[i] = besselKernel1D(m_scales[i], kernelSize); break; 00072 } 00073 } 00074 }