27 #include "../geometry/GTFactory.h"
28 #include "../common/PlatformUtils.h"
29 #include "../common/StringUtils.h"
30 #include "../raster/Band.h"
31 #include "../raster/Grid.h"
32 #include "../raster/BandProperty.h"
33 #include "../raster/RasterFactory.h"
34 #include "../datatype/Enums.h"
35 #include "../geometry/GTFilter.h"
37 #include <boost/scoped_array.hpp>
38 #include <boost/shared_array.hpp>
39 #include <boost/lexical_cast.hpp>
47 #include <boost/concept_check.hpp>
77 m_inMaskRaster1Ptr = 0;
78 m_inRaster1Bands.clear();
79 m_raster1TargetAreaLineStart = 0;
80 m_raster1TargetAreaColStart = 0;
81 m_raster1TargetAreaWidth = 0;
82 m_raster1TargetAreaHeight = 0;
84 m_inMaskRaster2Ptr = 0;
85 m_inRaster2Bands.clear();
86 m_raster2TargetAreaLineStart = 0;
87 m_raster2TargetAreaColStart = 0;
88 m_raster2TargetAreaWidth = 0;
89 m_raster2TargetAreaHeight = 0;
90 m_enableMultiThread =
true;
91 m_enableProgress =
false;
93 m_pixelSizeXRelation = 1;
94 m_pixelSizeYRelation = 1;
95 m_geomTransfName =
"Affine";
96 m_geomTransfMaxError = 2;
97 m_moravecCorrelationWindowWidth = 11;
98 m_moravecWindowWidth = 5;
99 m_maxR1ToR2Offset = 0;
100 m_enableGeometryFilter =
true;
101 m_geometryFilterAssurance = 0.1;
102 m_moravecGaussianFilterIterations = 1;
103 m_surfScalesNumber = 4;
104 m_surfOctavesNumber = 2;
105 m_rastersRescaleFactor = 1.0;
106 m_surfMaxNormEuclideanDist = 0.5;
107 m_moravecMinAbsCorrelation = 0.5;
180 m_transformationPtr.reset();
211 throw( te::rp::Exception )
222 double raster1XRescFact = 1.0;
223 double raster1YRescFact = 1.0;
224 double raster2XRescFact = 1.0;
225 double raster2YRescFact = 1.0;
266 std::auto_ptr< te::common::TaskProgress > progressPtr;
270 progressPtr->setTotalSteps( 1 );
271 progressPtr->setMessage(
"Locating tie points" );
272 progressPtr->pulse();
273 if( ! progressPtr->isActive() )
return false;
278 std::vector< double > tiePointsWeights;
292 "Moravec execution error" );
305 "SURF execution error" );
350 progressPtr->pulse();
351 if( ! progressPtr->isActive() )
return false;
358 const double raster1XRescFact,
359 const double raster1YRescFact,
360 const double raster2XRescFact,
361 const double raster2YRescFact,
364 std::vector< double >& tiePointsWeights )
365 throw( te::rp::Exception )
367 outParamsPtr->m_tiePoints.clear();
368 tiePointsWeights.clear();
375 double rescRaster1Area =
378 double rescRaster2Area =
382 if( rescRaster1Area > rescRaster2Area )
384 raster1MaxInterestPoints = (
unsigned int)(
388 else if( rescRaster1Area < rescRaster2Area )
390 raster2MaxInterestPoints = (
unsigned int)(
399 progressPtr->setTotalSteps( progressPtr->getTotalSteps() + 10 );
407 std::vector< boost::shared_ptr< FloatsMatrix > > raster1Data;
425 "Error loading raster data" );
429 progressPtr->pulse();
430 if( ! progressPtr->isActive() )
return false;
437 boost::shared_ptr< FloatsMatrix > tempMatrix(
442 raster1Data[ 0 ]->getMaxTmpFileSize(),
443 raster1Data[ 0 ]->getMaxMemPercentUsage() ),
444 "Cannot allocate image matrix" );
449 "Gaussian filter error" );
451 raster1Data[ 0 ]->reset();
452 raster1Data[ 0 ] = tempMatrix;
459 progressPtr->pulse();
460 if( ! progressPtr->isActive() )
return false;
469 raster1MaxInterestPoints,
471 raster1InterestPoints ),
472 "Error locating raster 1 interest points" );
476 progressPtr->pulse();
477 if( ! progressPtr->isActive() )
return false;
486 raster1InterestPoints,
491 "Error generating raster 1 features" );
493 raster1InterestPoints = auxInterestPoints;
499 progressPtr->pulse();
500 if( ! progressPtr->isActive() )
return false;
511 std::vector< boost::shared_ptr< FloatsMatrix > > raster2Data;
529 "Error loading raster data" );
533 progressPtr->pulse();
534 if( ! progressPtr->isActive() )
return false;
541 boost::shared_ptr< FloatsMatrix > tempMatrix(
548 raster2Data[ 0 ]->getMaxTmpFileSize(),
549 raster2Data[ 0 ]->getMaxMemPercentUsage() ),
550 "Cannot allocate image matrix" );
555 "Gaussian filter error" );
557 raster2Data[ 0 ] = tempMatrix;
564 progressPtr->pulse();
565 if( ! progressPtr->isActive() )
return false;
574 raster2MaxInterestPoints,
576 raster2InterestPoints ),
577 "Error locating raster 2 interest points" );
581 progressPtr->pulse();
582 if( ! progressPtr->isActive() )
return false;
591 raster2InterestPoints,
596 "Error generating raster 2 features" );
598 raster2InterestPoints = auxInterestPoints;
604 progressPtr->pulse();
605 if( ! progressPtr->isActive() )
return false;
616 raster1InterestPoints,
617 raster2InterestPoints,
622 "Error matching features" );
626 progressPtr->pulse();
627 if( ! progressPtr->isActive() )
return false;
632 raster1Features.
clear();
633 raster2Features.
clear();
634 raster1InterestPoints.clear();
635 raster2InterestPoints.clear();
641 MatchedInterestPointsSetT::const_iterator itB = matchedPoints.begin();
642 const MatchedInterestPointsSetT::const_iterator itE = matchedPoints.end();
644 float minFeatureValue1 = FLT_MAX;
645 float maxFeatureValue1 = (-1.0) * FLT_MAX;
646 float minFeatureValue2 = FLT_MAX;
647 float maxFeatureValue2 = (-1.0) * FLT_MAX;
648 float tiePointWeight = 0;
650 itB = matchedPoints.begin();
653 if( minFeatureValue1 > itB->m_point1.m_feature1 )
654 minFeatureValue1 = itB->m_point1.m_feature1;
655 if( maxFeatureValue1 < itB->m_point1.m_feature1 )
656 maxFeatureValue1 = itB->m_point1.m_feature1;
658 if( minFeatureValue2 > itB->m_point2.m_feature1 )
659 minFeatureValue2 = itB->m_point2.m_feature1;
660 if( maxFeatureValue2 < itB->m_point2.m_feature1 )
661 maxFeatureValue2 = itB->m_point2.m_feature1;
666 float featureValue1Range = maxFeatureValue1 - minFeatureValue1;
667 float featureValue2Range = maxFeatureValue2 - minFeatureValue2;
669 if( ( featureValue1Range == 0.0 ) || ( featureValue2Range == 0.0 ) )
671 tiePointsWeights.resize( matchedPoints.size(), 1.0 );
675 itB = matchedPoints.begin();
678 auxTP.first.x = ( itB->m_point1.m_x / raster1XRescFact ) +
680 auxTP.first.y = ( itB->m_point1.m_y / raster1YRescFact ) +
682 auxTP.second.x = ( itB->m_point2.m_x / raster2XRescFact ) +
684 auxTP.second.y = ( itB->m_point2.m_y / raster2YRescFact ) +
689 ( 2.0f * itB->m_feature )
693 ( itB->m_point1.m_feature1 - minFeatureValue1 )
699 ( itB->m_point1.m_feature2 - minFeatureValue2 )
706 tiePointsWeights.push_back( (
double)tiePointWeight );
708 outParamsPtr->m_tiePoints.push_back( auxTP );
717 progressPtr->pulse();
718 if( ! progressPtr->isActive() )
return false;
725 const double raster1XRescFact,
726 const double raster1YRescFact,
727 const double raster2XRescFact,
728 const double raster2YRescFact,
731 std::vector< double >& tiePointsWeights )
732 throw( te::rp::Exception )
734 outParamsPtr->m_tiePoints.clear();
735 tiePointsWeights.clear();
738 progressPtr->setTotalSteps( progressPtr->getTotalSteps() + 8 );
747 std::vector< boost::shared_ptr< FloatsMatrix > > rasterData;
765 "Error loading raster data" );
772 progressPtr->pulse();
773 if( ! progressPtr->isActive() )
return false;
781 integralRaster ),
"Integral image creation error" );
787 progressPtr->pulse();
788 if( ! progressPtr->isActive() )
return false;
799 raster1InterestPoints ),
800 "Error locating raster 1 interest points" );
806 progressPtr->pulse();
807 if( ! progressPtr->isActive() )
return false;
814 integralRaster, validInterestPoints, raster1Features ),
815 "Error generating raster features" );
817 raster1InterestPoints = validInterestPoints;
821 progressPtr->pulse();
822 if( ! progressPtr->isActive() )
return false;
834 std::vector< boost::shared_ptr< FloatsMatrix > > rasterData;
852 "Error loading raster data" );
859 progressPtr->pulse();
860 if( ! progressPtr->isActive() )
return false;
868 integralRaster ),
"Integral image creation error" );
872 progressPtr->pulse();
873 if( ! progressPtr->isActive() )
return false;
886 raster2InterestPoints ),
887 "Error locating raster interest points" );
893 progressPtr->pulse();
894 if( ! progressPtr->isActive() )
return false;
900 integralRaster, validInterestPoints, raster2Features ),
901 "Error generating raster features" );
903 raster2InterestPoints = validInterestPoints;
907 progressPtr->pulse();
908 if( ! progressPtr->isActive() )
return false;
922 raster1InterestPoints,
923 raster2InterestPoints,
928 "Error matching features" );
932 progressPtr->pulse();
933 if( ! progressPtr->isActive() )
return false;
940 MatchedInterestPointsSetT::iterator it1 = matchedPoints.begin();
941 MatchedInterestPointsSetT::iterator it2;
942 MatchedInterestPointsSetT::iterator eraseIt;
944 while( it1 != matchedPoints.end() )
948 eraseIt = matchedPoints.end();
950 while( it2 != matchedPoints.end() )
953 ( it1->m_point1.m_x == it2->m_point1.m_x )
955 ( it1->m_point1.m_y == it2->m_point1.m_y )
957 ( it1->m_point2.m_x == it2->m_point2.m_x )
959 ( it1->m_point2.m_y == it2->m_point2.m_y )
962 if( it1->m_feature < it2->m_feature )
966 else if( it1->m_feature > it2->m_feature )
982 matchedPoints.erase( eraseIt );
984 else if( eraseIt != matchedPoints.end() )
986 matchedPoints.erase( eraseIt );
1000 matchedPoints.erase( matchedPoints.begin() );
1007 MatchedInterestPointsSetT::const_iterator itB = matchedPoints.begin();
1008 const MatchedInterestPointsSetT::const_iterator itE = matchedPoints.end();
1009 float minFeature1P1 = FLT_MAX;
1010 float maxFeature1P1 = (-1.0) * FLT_MAX;
1011 float minFeature1P2 = FLT_MAX;
1012 float maxFeature1P2 = (-1.0) * FLT_MAX;
1016 if( minFeature1P1 > itB->m_point1.m_feature1 )
1017 minFeature1P1 = itB->m_point1.m_feature1;
1018 if( maxFeature1P1 < itB->m_point1.m_feature1 )
1019 maxFeature1P1 = itB->m_point1.m_feature1;
1021 if( minFeature1P2 > itB->m_point2.m_feature1 )
1022 minFeature1P2 = itB->m_point2.m_feature1;
1023 if( maxFeature1P2 < itB->m_point2.m_feature1 )
1024 maxFeature1P2 = itB->m_point2.m_feature1;
1029 float feature1P1Range = maxFeature1P1 - minFeature1P1;
1030 float feature1P2Range = maxFeature1P2 - minFeature1P2;
1032 if( ( feature1P1Range == 0.0 ) || ( feature1P2Range == 0.0 ) )
1034 tiePointsWeights.resize( matchedPoints.size(), 1.0 );
1038 itB = matchedPoints.begin();
1042 auxTP.first.x = ( itB->m_point1.m_x / raster1XRescFact ) +
1044 auxTP.first.y = ( itB->m_point1.m_y / raster1YRescFact ) +
1046 auxTP.second.x = ( itB->m_point2.m_x / raster2XRescFact ) +
1048 auxTP.second.y = ( itB->m_point2.m_y / raster2YRescFact ) +
1051 tiePointsWeights.push_back( (
double)
1053 ( 2.0 * itB->m_feature )
1057 ( itB->m_point1.m_feature1 - minFeature1P1 + feature1P1Range )
1059 ( 2.0 * feature1P1Range )
1063 ( itB->m_point2.m_feature1 - minFeature1P2 + feature1P2Range )
1065 ( 2.0 * feature1P2Range )
1071 outParamsPtr->m_tiePoints.push_back( auxTP );
1089 throw( te::rp::Exception )
1104 "Invalid m_inRaster1Ptr" );
1107 "Invalid m_inRaster1Ptr" );
1115 "Invalid m_inMaskRaster1Ptr" );
1118 "Invalid m_inMaskRaster1Ptr" );
1122 "Invalid m_inMaskRaster1Ptr" );
1126 "Invalid m_inMaskRaster1Ptr" );
1133 "Invalid m_raster1TargetAreaLineStart" );
1137 "Invalid m_raster1TargetAreaColStart" );
1161 "Invalid m_raster1TargetAreaWidth" );
1163 "Invalid m_raster1TargetAreaHeight" );
1167 for(
unsigned int bandIdx = 0 ; bandIdx <
1173 "Invalid m_inRaster1Bands" );
1180 "Invalid m_inRaster2Ptr" );
1183 "Invalid m_inRaster2Ptr" );
1191 "Invalid m_inMaskRaster2Ptr" );
1194 "Invalid m_inMaskRaster2Ptr" );
1198 "Invalid m_inMaskRaster2Ptr" );
1202 "Invalid m_inMaskRaster2Ptr" );
1209 "Invalid m_raster2TargetAreaLineStart" );
1213 "Invalid m_raster2TargetAreaColStart" );
1237 "Invalid m_raster2TargetAreaWidth" );
1239 "Invalid m_raster2TargetAreaHeight" );
1244 for(
unsigned int bandIdx = 0 ; bandIdx <
1250 "Invalid m_inRaster2Bands" );
1261 == 1,
"Invalid number of raster 1 bands" );
1263 == 1,
"Invalid number of raster 2 bands" );
1269 const unsigned int maxRastersArea =
1277 const unsigned maxWindowSize = std::max(
1281 ( 4 * maxWindowSize * maxWindowSize );
1287 const double freeVMem = 0.4 * std::min( totalPhysMem, ( totalVMem - usedVMem ) );
1295 ( featSize * featSize )
1297 ( freeVMem / (
double)(
sizeof(
float ) ) )
1310 == 1,
"Invalid number of raster 1 bands" );
1312 == 1,
"Invalid number of raster 2 bands" );
1318 const unsigned int maxRastersArea =
1330 ( 4 * maxWindowSize * maxWindowSize );
1336 const double freeVMem = 0.4 * std::min( totalPhysMem, ( totalVMem - usedVMem ) );
1344 ( freeVMem / (
double)(
sizeof(
float ) ) )
1364 "Invalid m_maxTiePoints" )
1367 "Invalid m_pixelSizeXRelation" )
1370 "Invalid m_pixelSizeYRelation" )
1373 "Invalid m_geomTransfMaxError" )
1378 "Invalid m_moravecCorrelationWindowWidth" );
1383 "Invalid m_moravecWindowWidth" );
1387 "Invalid m_geomTransfName" );
1390 "Invalid m_surfScalesNumber" );
1393 "Invalid m_surfOctavesNumber" );
1396 "Invalid m_rastersRescaleFactor" );
1400 "Invalid m_surfMaxNormEuclideanDist" );
1404 "Invalid m_moravecMinAbsCorrelation" );
1408 "Invalid m_geometryFilterAssurance" );
1422 const std::vector< unsigned int >& rasterBands,
1424 const unsigned int maskRasterBand,
1425 const unsigned int rasterTargetAreaLineStart,
1426 const unsigned int rasterTargetAreaColStart,
1427 const unsigned int rasterTargetAreaWidth,
1428 const unsigned int rasterTargetAreaHeight,
1429 const double rescaleFactorX,
1430 const double rescaleFactorY,
1432 const unsigned char maxMemPercentUsage,
1433 std::vector< boost::shared_ptr< FloatsMatrix > >& loadedRasterData,
1438 const unsigned int rescaledNLines = (
unsigned int)(
1439 ((
double)rasterTargetAreaHeight) * rescaleFactorY );
1440 const unsigned int rescaledNCols = (
unsigned int)(
1441 ((
double)rasterTargetAreaWidth) * rescaleFactorX );
1444 unsigned char maxMemPercentUsagePerMatrix =
MAX( 1u, maxMemPercentUsage /
1446 ( maskRasterPtr ? 1 : 0 )
1448 ((
unsigned int)rasterBands.size()) )
1451 loadedRasterData.resize( rasterBands.size() );
1453 for(
unsigned int rasterBandsIdx = 0 ; rasterBandsIdx < rasterBands.size() ;
1456 loadedRasterData[ rasterBandsIdx ].reset(
new FloatsMatrix );
1459 maxMemPercentUsagePerMatrix ),
1460 "Cannot allocate image 1 matrix" );
1461 maxMemPercentUsagePerMatrix *= 2;
1467 rescaledNLines, rescaledNCols,
1469 "Cannot allocate image 1 mask matrix" );
1478 assert( inMaskRasterBand );
1480 unsigned char* outMaskLinePtr = 0;
1481 unsigned int outLine = 0;
1482 unsigned int outCol = 0;
1483 unsigned int inLine = 0;
1484 unsigned int inCol = 0;
1487 for( outLine = 0 ; outLine < rescaledNLines ; ++outLine )
1489 inLine = (
unsigned int)( ( ( (
double)outLine ) /
1490 rescaleFactorY ) + ( (double)rasterTargetAreaLineStart ) );
1492 outMaskLinePtr = loadedMaskRasterData[ outLine ];
1494 for( outCol = 0 ; outCol < rescaledNCols ; ++outCol )
1496 inCol = (
unsigned int)( ( ( (
double)outCol ) /
1497 rescaleFactorX ) + ( (double)rasterTargetAreaColStart ) );
1499 inMaskRasterBand->
getValue( inCol, inLine, value );
1502 outMaskLinePtr[ outCol ] = 0;
1504 outMaskLinePtr[ outCol ] = 255;
1511 const double rasterTargetAreaLineStartDouble = (double)
1512 rasterTargetAreaLineStart;
1513 const double rasterTargetAreaColStartDouble = (double)
1514 rasterTargetAreaColStart;
1516 float* floatLinePtr = 0;
1517 double* doubleLinePtr = 0;
1518 unsigned int outLine = 0;
1519 unsigned int outCol = 0;
1522 std::complex< double > interpolatedValue;
1523 unsigned int bandIdx = 0;
1531 "Cannot allocate auxiliar matrix" );
1533 for(
unsigned int rasterBandsIdx = 0 ; rasterBandsIdx < rasterBands.size() ;
1536 bandIdx= rasterBands[ rasterBandsIdx ];
1538 bandMax = -1.0 * DBL_MAX;
1540 for( outLine = 0 ; outLine < rescaledNLines ; ++outLine )
1542 inLine = ( ( (double)outLine ) / rescaleFactorY ) +
1543 rasterTargetAreaLineStartDouble;
1545 doubleLinePtr = auxBandData[ outLine ];
1547 for( outCol = 0 ; outCol < rescaledNCols ; ++outCol )
1549 inCol = ( ( (double)outCol ) / rescaleFactorX ) +
1550 rasterTargetAreaColStartDouble;
1552 interpInstance.
getValue( inCol, inLine, interpolatedValue,
1555 doubleLinePtr[ outCol ] = interpolatedValue.real();
1557 if( interpolatedValue.real() > bandMax ) bandMax = interpolatedValue.real();
1558 if( interpolatedValue.real() < bandMin ) bandMin = interpolatedValue.real();
1562 if( bandMin == bandMax )
1565 gain = ( 1.0 / ( bandMax - bandMin ) );
1567 for( outLine = 0 ; outLine < rescaledNLines ; ++outLine )
1569 doubleLinePtr = auxBandData[ outLine ];
1570 floatLinePtr = loadedRasterData[ rasterBandsIdx ]->operator[]( outLine );
1572 for( outCol = 0 ; outCol < rescaledNCols ; ++outCol )
1574 floatLinePtr[ outCol ] = (float)( ( doubleLinePtr[ outCol ] - bandMin ) * gain );
1586 const unsigned int moravecWindowWidth,
1587 const unsigned int maxInterestPoints,
1588 const unsigned int enableMultiThread,
1591 interestPoints.clear();
1593 const unsigned int minRasterWidthAndHeight = 2 * ( ( 2 *
1594 moravecWindowWidth ) - 1 );
1597 if( rasterData.
getLinesNumber() < minRasterWidthAndHeight )
return true;
1599 bool returnValue =
true;
1600 boost::mutex rastaDataAccessMutex;
1601 boost::mutex interestPointsAccessMutex;
1602 unsigned int nextRasterLinesBlockToProcess = 0;
1609 &nextRasterLinesBlockToProcess;
1615 if( enableMultiThread )
1620 minRasterWidthAndHeight, rasterData.
getLinesNumber() / procsNumber );
1622 const unsigned int rasterLinesBlocksNumber =
1627 maxInterestPoints / rasterLinesBlocksNumber;
1629 boost::thread_group threads;
1631 for(
unsigned int threadIdx = 0 ; threadIdx < procsNumber ;
1634 threads.add_thread(
new boost::thread(
1654 assert( paramsPtr );
1665 const unsigned int moravecWindowRadius = moravecWindowWidth / 2;
1673 const unsigned int bufferLines = moravecWindowWidth;
1674 const unsigned int lastBufferLineIdx = bufferLines - 1;
1676 const unsigned int rasterBufferLineSizeBytes =
sizeof(
1678 const unsigned int maskRasterBufferLineSizeBytes =
sizeof(
1685 if( ! rasterBufferDataHandler.
reset( bufferLines, bufferCols,
1694 boost::scoped_array< float* > rasterBufferHandler(
new float*[ bufferLines ] );
1695 for(
unsigned int rasterBufferDataHandlerLine = 0 ; rasterBufferDataHandlerLine <
1696 bufferLines ; ++rasterBufferDataHandlerLine )
1698 rasterBufferHandler[ rasterBufferDataHandlerLine ] = rasterBufferDataHandler[
1699 rasterBufferDataHandlerLine ];
1702 float** rasterBufferPtr = rasterBufferHandler.get();
1708 boost::scoped_array< unsigned char* > maskRasterBufferHandler(
new unsigned char*[ bufferLines ] );
1710 unsigned char** maskRasterBufferPtr = 0;
1714 if( ! maskRasterBufferDataHandler.
reset( bufferLines, bufferCols,
1723 for(
unsigned int maskRasterBufferDataHandlerLine = 0 ; maskRasterBufferDataHandlerLine <
1724 bufferLines ; ++maskRasterBufferDataHandlerLine )
1726 maskRasterBufferHandler[ maskRasterBufferDataHandlerLine ] = maskRasterBufferDataHandler[
1727 maskRasterBufferDataHandlerLine ];
1730 maskRasterBufferPtr = maskRasterBufferHandler.get();
1736 if( ! maximasBufferDataHandler.
reset( bufferLines, bufferCols,
1745 boost::scoped_array< float* > maximasBufferHandler(
new float*[ bufferLines ] );
1746 float** maximasBufferPtr = maximasBufferHandler.get();
1747 unsigned int bufferCol = 0;
1748 for(
unsigned int maximasBufferDataHandlerLine = 0 ; maximasBufferDataHandlerLine <
1749 bufferLines ; ++maximasBufferDataHandlerLine )
1751 maximasBufferHandler[ maximasBufferDataHandlerLine ] = maximasBufferDataHandler[
1752 maximasBufferDataHandlerLine ];
1753 for( bufferCol = 0 ; bufferCol < bufferCols ; ++bufferCol )
1755 maximasBufferPtr[ maximasBufferDataHandlerLine ][ bufferCol ] = 0;
1761 const unsigned int rasterLinesBlocksNumber =
1765 for(
unsigned int rasterLinesBlockIdx = 0; rasterLinesBlockIdx <
1766 rasterLinesBlocksNumber ; ++rasterLinesBlockIdx )
1780 const unsigned int rasterLinesStart = (
unsigned int)std::max( 0,
1782 (
int)( 2 * moravecWindowRadius ) );
1783 const unsigned int rasterLinesEndBound = std::min( 1 +
1786 ( 2 * moravecWindowRadius ), rasterLines );
1787 const unsigned int varianceCalcStartRasterLineStart = rasterLinesStart +
1788 moravecWindowWidth - 1;
1789 const unsigned int maximasLocationStartRasterLineStart =
1790 varianceCalcStartRasterLineStart + moravecWindowWidth - 1;
1791 unsigned int windowStartBufCol = 0;
1792 const unsigned int windowEndBufColsBound = bufferCols -
1794 unsigned int windowStartBufOffset = 0;
1795 unsigned int windowStartBufXOffset = 0;
1796 unsigned int windowStartBufYOffset = 0;
1801 float diffValue = 0;
1802 bool isLocalMaxima =
false;
1804 float neighborMaximaDif = 0;
1806 for(
unsigned int rasterLine = rasterLinesStart; rasterLine < rasterLinesEndBound ;
1813 memcpy( rasterBufferPtr[ lastBufferLineIdx ],
1815 rasterBufferLineSizeBytes );
1821 memcpy( maskRasterBufferPtr[ lastBufferLineIdx ],
1823 maskRasterBufferLineSizeBytes );
1830 if( rasterLine >= varianceCalcStartRasterLineStart )
1834 for( windowStartBufCol = 0 ; windowStartBufCol < windowEndBufColsBound ;
1835 ++windowStartBufCol )
1837 const float& windowCenterPixelValue = rasterBufferPtr[
1838 moravecWindowRadius ][ windowStartBufCol +
1839 moravecWindowRadius ];
1845 for( windowStartBufOffset = 0 ; windowStartBufOffset <
1846 moravecWindowWidth ; ++windowStartBufOffset )
1848 diffValue = windowCenterPixelValue - rasterBufferPtr[
1849 moravecWindowRadius ][ windowStartBufCol +
1850 windowStartBufOffset ];
1851 horVar += ( diffValue * diffValue );
1853 diffValue = windowCenterPixelValue - rasterBufferPtr[
1854 windowStartBufOffset ][ windowStartBufCol +
1855 moravecWindowRadius ];
1856 verVar += ( diffValue * diffValue );
1858 diffValue = windowCenterPixelValue - rasterBufferPtr[
1859 windowStartBufOffset ][ windowStartBufCol +
1860 windowStartBufOffset ];
1861 diagVar += ( diffValue * diffValue );
1863 diffValue = windowCenterPixelValue - rasterBufferPtr[
1864 moravecWindowWidth - 1 - windowStartBufOffset ][ windowStartBufCol +
1865 windowStartBufOffset ];
1866 adiagVar += ( diffValue * diffValue );
1869 maximasBufferPtr[ lastBufferLineIdx ][ windowStartBufCol +
1870 moravecWindowRadius ] = std::min( horVar, std::min(
1871 verVar, std::min( diagVar, adiagVar ) ) );
1877 if( rasterLine >= maximasLocationStartRasterLineStart )
1879 for( windowStartBufCol = 0 ; windowStartBufCol < windowEndBufColsBound ;
1880 ++windowStartBufCol )
1882 isLocalMaxima =
true;
1883 const float& windowCenterPixelValue = maximasBufferPtr[
1884 moravecWindowRadius ][ windowStartBufCol +
1885 moravecWindowRadius ];
1888 for( windowStartBufYOffset = 0 ; windowStartBufYOffset <
1889 moravecWindowWidth ; ++windowStartBufYOffset )
1891 for( windowStartBufXOffset = 0 ; windowStartBufXOffset <
1892 moravecWindowWidth ; ++windowStartBufXOffset )
1894 neighborMaximaDif = windowCenterPixelValue - maximasBufferPtr[
1895 windowStartBufYOffset ][ windowStartBufCol +
1896 windowStartBufXOffset ];
1898 if( neighborMaximaDif < 0.0 )
1900 isLocalMaxima =
false;
1901 windowStartBufYOffset = moravecWindowWidth;
1905 auxInterestPoint.
m_feature1 += std::abs( neighborMaximaDif );
1911 auxInterestPoint.
m_x = windowStartBufCol +
1912 moravecWindowRadius;
1913 auxInterestPoint.
m_y = rasterLine - moravecWindowWidth + 1;
1914 assert( auxInterestPoint.
m_x <
1916 assert( auxInterestPoint.
m_y <
1919 if( maskRasterBufferPtr )
1921 if( maskRasterBufferPtr[ 0 ][ auxInterestPoint.
m_x ] )
1923 blockMaximas.insert( auxInterestPoint);
1925 if( blockMaximas.size() >
1928 blockMaximas.erase( blockMaximas.begin() );
1934 blockMaximas.insert( auxInterestPoint );
1936 if( blockMaximas.size() >
1939 blockMaximas.erase( blockMaximas.begin() );
1951 unsigned int pointsToAdd = std::min(
1953 (
unsigned int)blockMaximas.size() );
1954 InterestPointsSetT::const_reverse_iterator blockMaximasIt =
1955 blockMaximas.rbegin();
1957 while( pointsToAdd )
1982 interestPoints.clear();
1986 bool returnValue =
true;
1987 boost::mutex rastaDataAccessMutex;
1988 boost::mutex interestPointsAccessMutex;
1989 unsigned int nextRasterLinesBlockToProcess = 0;
1996 &nextRasterLinesBlockToProcess;
2010 4 * maxGausFilterWidth, integralRasterData.
getLinesNumber() / procsNumber );
2015 const unsigned int rasterLinesBlocksNumber =
2022 boost::thread_group threads;
2024 for(
unsigned int threadIdx = 0 ; threadIdx < procsNumber ;
2027 threads.add_thread(
new boost::thread(
2049 assert( paramsPtr );
2064 const unsigned int maxGausFilterRadius = maxGausFilterWidth / 2;
2065 const unsigned int prevResponseBufferLineIdx = maxGausFilterRadius - 1;
2066 const unsigned int nextResponseBufferLineIdx = maxGausFilterRadius + 1;
2067 const unsigned int buffersLines = maxGausFilterWidth;
2068 const unsigned int lastBuffersLineIdx = buffersLines - 1;
2073 const unsigned int rasterBufferLineSizeBytes =
sizeof( float ) *
2079 const unsigned maxGausFilterCenterBufferColBound = buffersCols -
2080 maxGausFilterRadius;
2082 unsigned int scaleIdx = 0 ;
2083 unsigned int octaveIdx = 0 ;
2089 boost::scoped_array< float* > rasterBufferHandler(
new float*[ buffersLines ] );
2091 if( ! rasterBufferDataHandler.
reset( buffersLines, buffersCols,
2100 for(
unsigned int rasterBufferDataHandlerLine = 0 ; rasterBufferDataHandlerLine <
2101 buffersLines ; ++rasterBufferDataHandlerLine )
2103 rasterBufferHandler[ rasterBufferDataHandlerLine ] = rasterBufferDataHandler[
2104 rasterBufferDataHandlerLine ];
2107 float** rasterBufferPtr = rasterBufferHandler.get();
2113 boost::scoped_array< unsigned char* > maskRasterBufferHandler(
new unsigned char*[ buffersLines ] );
2115 unsigned char** maskRasterBufferPtr = 0;
2119 if( ! maskRasterBufferDataHandler.
reset( buffersLines, buffersCols,
2128 for(
unsigned int maskRasterBufferDataHandlerLine = 0 ; maskRasterBufferDataHandlerLine <
2129 buffersLines ; ++maskRasterBufferDataHandlerLine )
2131 maskRasterBufferHandler[ maskRasterBufferDataHandlerLine ] = maskRasterBufferDataHandler[
2132 maskRasterBufferDataHandlerLine ];
2135 maskRasterBufferPtr = maskRasterBufferHandler.get();
2141 std::vector< std::vector< boost::shared_array< float* > > >
2142 octavesBufferHandlers;
2144 const unsigned int octavesBufferDataHandlerLines =
2146 if( ! octavesBufferDataHandler.
reset( octavesBufferDataHandlerLines ,
2155 unsigned int octavesBufferDataHandlerLine = 0;
2156 unsigned int octavesBufferDataHandlerCol = 0;
2157 float* octavesBufferDataHandlerLinePtr = 0;
2158 for( octavesBufferDataHandlerLine = 0; octavesBufferDataHandlerLine <
2159 octavesBufferDataHandlerLines ; ++octavesBufferDataHandlerLine )
2161 octavesBufferDataHandlerLinePtr = octavesBufferDataHandler[
2162 octavesBufferDataHandlerLine ];
2164 for( octavesBufferDataHandlerCol = 0; octavesBufferDataHandlerCol <
2165 buffersCols ; ++octavesBufferDataHandlerCol )
2167 octavesBufferDataHandlerLinePtr[ octavesBufferDataHandlerCol ] = 0.0;
2171 octavesBufferDataHandlerLine = 0;
2172 for( octaveIdx = 0 ; octaveIdx < paramsPtr->
m_octavesNumber ; ++octaveIdx )
2174 octavesBufferHandlers.push_back( std::vector< boost::shared_array< float* > >() );
2175 std::vector< boost::shared_array< float* > >&
2176 currOctaveBuffersHandler = octavesBufferHandlers.back();
2178 for( scaleIdx = 0 ; scaleIdx < paramsPtr->
m_scalesNumber ; ++scaleIdx )
2180 currOctaveBuffersHandler.push_back( boost::shared_array< float* >(
2181 new float*[ buffersLines ] ) );
2182 boost::shared_array< float* >& currOctavesBuffer =
2183 currOctaveBuffersHandler.back();
2184 for(
unsigned int bufferLine = 0 ; bufferLine < buffersLines ;
2187 assert( octavesBufferDataHandlerLine <
2190 currOctavesBuffer[ bufferLine ] = octavesBufferDataHandler[
2191 octavesBufferDataHandlerLine ];
2193 ++octavesBufferDataHandlerLine;
2202 std::vector< std::vector< boost::shared_array< unsigned char* > > >
2203 laplacianSignBufferHandlers;
2205 const unsigned int laplacianSignBufferDataHandlerLines =
2207 if( ! laplacianSignBufferDataHandler.
reset( laplacianSignBufferDataHandlerLines ,
2216 unsigned int laplacianSignBufferDataHandlerLine = 0;
2217 unsigned int laplacianSignBufferDataHandlerCol = 0;
2218 unsigned char* laplacianSignBufferDataHandlerLinePtr = 0;
2219 for( laplacianSignBufferDataHandlerLine = 0; laplacianSignBufferDataHandlerLine <
2220 laplacianSignBufferDataHandlerLines ; ++laplacianSignBufferDataHandlerLine )
2222 laplacianSignBufferDataHandlerLinePtr = laplacianSignBufferDataHandler[
2223 laplacianSignBufferDataHandlerLine ];
2225 for( laplacianSignBufferDataHandlerCol = 0; laplacianSignBufferDataHandlerCol <
2226 buffersCols ; ++laplacianSignBufferDataHandlerCol )
2228 laplacianSignBufferDataHandlerLinePtr[ laplacianSignBufferDataHandlerCol ] =
2233 laplacianSignBufferDataHandlerLine = 0;
2234 for( octaveIdx = 0 ; octaveIdx < paramsPtr->
m_octavesNumber ; ++octaveIdx )
2236 laplacianSignBufferHandlers.push_back( std::vector< boost::shared_array< unsigned char* > >() );
2237 std::vector< boost::shared_array< unsigned char* > >&
2238 currlaplacianSignBuffersHandler = laplacianSignBufferHandlers.back();
2240 for( scaleIdx = 0 ; scaleIdx < paramsPtr->
m_scalesNumber ; ++scaleIdx )
2242 currlaplacianSignBuffersHandler.push_back( boost::shared_array< unsigned char* >(
2243 new unsigned char*[ buffersLines ] ) );
2244 boost::shared_array< unsigned char* >& currlaplacianSignBuffer =
2245 currlaplacianSignBuffersHandler.back();
2246 for(
unsigned int bufferLine = 0 ; bufferLine < buffersLines ;
2249 assert( laplacianSignBufferDataHandlerLine <
2252 currlaplacianSignBuffer[ bufferLine ] = laplacianSignBufferDataHandler[
2253 laplacianSignBufferDataHandlerLine ];
2255 ++laplacianSignBufferDataHandlerLine;
2263 const unsigned int rasterLinesBlocksNumber =
2267 for(
unsigned int rasterLinesBlockIdx = 0; rasterLinesBlockIdx <
2268 rasterLinesBlocksNumber ; ++rasterLinesBlockIdx )
2272 std::vector< InterestPointsSetT > blockMaximas( paramsPtr->
m_scalesNumber *
2285 const unsigned int rasterLinesStart = (
unsigned int)std::max( 0,
2287 (
int)( 2 * maxGausFilterRadius ) );
2288 const unsigned int rasterLinesEndBound = std::min( 1 +
2291 ( 2 * maxGausFilterRadius ), rasterLines );
2292 const unsigned int firstRasterLineToGenerateResponse =
2293 rasterLinesStart + maxGausFilterWidth - 1;
2294 const unsigned int firstRasterLineToLookForMaximas =
2295 firstRasterLineToGenerateResponse + maxGausFilterRadius + 1;
2298 unsigned int filterWidth = 0;
2299 unsigned int filterLobeWidth = 0;
2300 unsigned int filterLobeRadius = 0;
2301 unsigned int filterCenterBufCol = 0 ;
2307 float** currScaleBufferPtr = 0;
2308 unsigned char** currLaplacianSignBufferPtr = 0;
2309 unsigned int lastScaleIdx = 0;
2310 unsigned int nextScaleIdx = 0;
2311 unsigned int prevResponseBufferColIdx = 0;
2312 unsigned int nextResponseBufferColIdx = 0;
2314 float neighborMaximaDif_0_1 = 0.0;
2315 float neighborMaximaDif_0_2 = 0.0;
2316 float neighborMaximaDif_0_3 = 0.0;
2317 float neighborMaximaDif_0_4 = 0.0;
2318 float neighborMaximaDif_0_5 = 0.0;
2319 float neighborMaximaDif_0_6 = 0.0;
2320 float neighborMaximaDif_0_7 = 0.0;
2321 float neighborMaximaDif_0_8 = 0.0;
2322 float neighborMaximaDif_1_1 = 0.0;
2323 float neighborMaximaDif_1_2 = 0.0;
2324 float neighborMaximaDif_1_3 = 0.0;
2325 float neighborMaximaDif_1_4 = 0.0;
2326 float neighborMaximaDif_1_5 = 0.0;
2327 float neighborMaximaDif_1_6 = 0.0;
2328 float neighborMaximaDif_1_7 = 0.0;
2329 float neighborMaximaDif_1_8 = 0.0;
2330 float neighborMaximaDif_1_9 = 0.0;
2331 float neighborMaximaDif_2_1 = 0.0;
2332 float neighborMaximaDif_2_2 = 0.0;
2333 float neighborMaximaDif_2_3 = 0.0;
2334 float neighborMaximaDif_2_4 = 0.0;
2335 float neighborMaximaDif_2_5 = 0.0;
2336 float neighborMaximaDif_2_6 = 0.0;
2337 float neighborMaximaDif_2_7 = 0.0;
2338 float neighborMaximaDif_2_8 = 0.0;
2339 float neighborMaximaDif_2_9 = 0.0;
2343 for(
unsigned int rasterLine = rasterLinesStart; rasterLine < rasterLinesEndBound ;
2352 memcpy( rasterBufferPtr[ lastBuffersLineIdx ],
2354 rasterBufferLineSizeBytes );
2360 memcpy( maskRasterBufferPtr[ lastBuffersLineIdx ],
2362 maskRasterBufferLineSizeBytes );
2368 if( rasterLine >= firstRasterLineToGenerateResponse )
2370 for( octaveIdx = 0 ; octaveIdx < paramsPtr->
m_octavesNumber ; ++octaveIdx )
2375 assert( octavesBufferHandlers.size() > octaveIdx );
2376 assert( octavesBufferHandlers[ octaveIdx].size() > scaleIdx );
2377 currScaleBufferPtr = octavesBufferHandlers[ octaveIdx][ scaleIdx ].get();
2378 assert( currScaleBufferPtr );
2380 assert( laplacianSignBufferHandlers.size() > octaveIdx );
2381 assert( laplacianSignBufferHandlers[ octaveIdx].size() > scaleIdx );
2382 currLaplacianSignBufferPtr = laplacianSignBufferHandlers[ octaveIdx][ scaleIdx ].get();
2383 assert( currLaplacianSignBufferPtr );
2388 roolUpBuffer( currLaplacianSignBufferPtr, buffersLines );
2393 assert( filterWidth <= maxGausFilterWidth );
2395 filterLobeWidth = filterWidth / 3;
2396 filterLobeRadius = filterLobeWidth / 2;
2398 for( filterCenterBufCol = maxGausFilterRadius ;
2399 filterCenterBufCol < maxGausFilterCenterBufferColBound ;
2400 ++filterCenterBufCol )
2403 maxGausFilterRadius, filterLobeWidth, filterLobeRadius);
2404 dYY /= (float)( filterWidth * filterWidth );
2407 maxGausFilterRadius, filterLobeWidth, filterLobeRadius);
2408 dXX /= (float)( filterWidth * filterWidth );
2411 maxGausFilterRadius, filterLobeWidth );
2412 dXY /= (float)( filterWidth * filterWidth );
2414 currScaleBufferPtr[ lastBuffersLineIdx ][ filterCenterBufCol ] =
2415 ( dXX * dYY ) - ( 0.81f * dXY * dXY );
2416 currLaplacianSignBufferPtr[ lastBuffersLineIdx ][ filterCenterBufCol ] =
2417 ( ( dXX + dYY ) >= 0.0 ) ? 1 : 0;
2426 if( rasterLine >= firstRasterLineToLookForMaximas )
2433 for(
unsigned int windCenterCol = maxGausFilterRadius ;
2434 windCenterCol < maxGausFilterCenterBufferColBound ; ++windCenterCol )
2436 prevResponseBufferColIdx = windCenterCol - 1;
2437 nextResponseBufferColIdx = windCenterCol + 1;
2438 auxInterestPoint.
m_feature1 = (-1.0) * FLT_MAX;
2440 for( octaveIdx = 0 ; octaveIdx < paramsPtr->
m_octavesNumber ; ++octaveIdx )
2442 std::vector< boost::shared_array< float* > >&
2443 currOctaveBuffersHandler = octavesBufferHandlers[ octaveIdx ];
2445 for( scaleIdx = 1 ; scaleIdx < ( paramsPtr->
m_scalesNumber - 1 );
2448 const float& windowCenterPixelValue = currOctaveBuffersHandler[
2449 scaleIdx ][ maxGausFilterRadius ][ windCenterCol ];
2450 lastScaleIdx = scaleIdx - 1;
2451 nextScaleIdx = scaleIdx + 1;
2453 neighborMaximaDif_0_1 = windowCenterPixelValue - currOctaveBuffersHandler[
2454 scaleIdx ][ prevResponseBufferLineIdx ][ prevResponseBufferColIdx ];
2455 neighborMaximaDif_0_2 = windowCenterPixelValue - currOctaveBuffersHandler[
2456 scaleIdx ][ prevResponseBufferLineIdx ][ windCenterCol ];
2457 neighborMaximaDif_0_3 = windowCenterPixelValue - currOctaveBuffersHandler[
2458 scaleIdx ][ prevResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2459 neighborMaximaDif_0_4 = windowCenterPixelValue - currOctaveBuffersHandler[
2460 scaleIdx ][ maxGausFilterRadius ][ prevResponseBufferColIdx ];
2461 neighborMaximaDif_0_5 = windowCenterPixelValue - currOctaveBuffersHandler[
2462 scaleIdx ][ maxGausFilterRadius ][ nextResponseBufferColIdx ];
2463 neighborMaximaDif_0_6 = windowCenterPixelValue - currOctaveBuffersHandler[
2464 scaleIdx ][ nextResponseBufferLineIdx ][ prevResponseBufferColIdx];
2465 neighborMaximaDif_0_7 = windowCenterPixelValue - currOctaveBuffersHandler[
2466 scaleIdx ][ nextResponseBufferLineIdx ][ windCenterCol ];
2467 neighborMaximaDif_0_8 = windowCenterPixelValue - currOctaveBuffersHandler[
2468 scaleIdx ][ nextResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2471 ( windowCenterPixelValue > 0.0 )
2473 && ( neighborMaximaDif_0_1 > 0.0 )
2474 && ( neighborMaximaDif_0_2 > 0.0 )
2475 && ( neighborMaximaDif_0_3 > 0.0 )
2476 && ( neighborMaximaDif_0_4 > 0.0 )
2477 && ( neighborMaximaDif_0_5 > 0.0 )
2478 && ( neighborMaximaDif_0_6 > 0.0 )
2479 && ( neighborMaximaDif_0_7 > 0.0 )
2480 && ( neighborMaximaDif_0_8 > 0.0 )
2483 neighborMaximaDif_1_1 = windowCenterPixelValue - currOctaveBuffersHandler[
2484 lastScaleIdx ][ prevResponseBufferLineIdx ][ prevResponseBufferColIdx ];
2485 neighborMaximaDif_1_2 = windowCenterPixelValue - currOctaveBuffersHandler[
2486 lastScaleIdx ][ prevResponseBufferLineIdx ][ windCenterCol ];
2487 neighborMaximaDif_1_3 = windowCenterPixelValue - currOctaveBuffersHandler[
2488 lastScaleIdx ][ prevResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2489 neighborMaximaDif_1_4 = windowCenterPixelValue - currOctaveBuffersHandler[
2490 lastScaleIdx ][ maxGausFilterRadius ][ prevResponseBufferColIdx ];
2491 neighborMaximaDif_1_5 = windowCenterPixelValue - currOctaveBuffersHandler[
2492 lastScaleIdx ][ maxGausFilterRadius ][ windCenterCol ];
2493 neighborMaximaDif_1_6 = windowCenterPixelValue - currOctaveBuffersHandler[
2494 lastScaleIdx ][ maxGausFilterRadius ][ nextResponseBufferColIdx ];
2495 neighborMaximaDif_1_7 = windowCenterPixelValue - currOctaveBuffersHandler[
2496 lastScaleIdx ][ nextResponseBufferLineIdx ][ prevResponseBufferColIdx];
2497 neighborMaximaDif_1_8 = windowCenterPixelValue - currOctaveBuffersHandler[
2498 lastScaleIdx ][ nextResponseBufferLineIdx ][ windCenterCol ];
2499 neighborMaximaDif_1_9 = windowCenterPixelValue - currOctaveBuffersHandler[
2500 lastScaleIdx ][ nextResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2504 ( neighborMaximaDif_1_1 > 0.0 )
2505 && ( neighborMaximaDif_1_2 > 0.0 )
2506 && ( neighborMaximaDif_1_3 > 0.0 )
2507 && ( neighborMaximaDif_1_4 > 0.0 )
2508 && ( neighborMaximaDif_1_5 > 0.0 )
2509 && ( neighborMaximaDif_1_6 > 0.0 )
2510 && ( neighborMaximaDif_1_7 > 0.0 )
2511 && ( neighborMaximaDif_1_8 > 0.0 )
2512 && ( neighborMaximaDif_1_9 > 0.0 )
2515 neighborMaximaDif_2_1 = windowCenterPixelValue - currOctaveBuffersHandler[
2516 nextScaleIdx ][ prevResponseBufferLineIdx ][ prevResponseBufferColIdx ];
2517 neighborMaximaDif_2_2 = windowCenterPixelValue - currOctaveBuffersHandler[
2518 nextScaleIdx ][ prevResponseBufferLineIdx ][ windCenterCol ];
2519 neighborMaximaDif_2_3 = windowCenterPixelValue - currOctaveBuffersHandler[
2520 nextScaleIdx ][ prevResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2521 neighborMaximaDif_2_4 = windowCenterPixelValue - currOctaveBuffersHandler[
2522 nextScaleIdx ][ maxGausFilterRadius ][ prevResponseBufferColIdx ];
2523 neighborMaximaDif_2_5 = windowCenterPixelValue - currOctaveBuffersHandler[
2524 nextScaleIdx ][ maxGausFilterRadius ][ windCenterCol ];
2525 neighborMaximaDif_2_6 = windowCenterPixelValue - currOctaveBuffersHandler[
2526 nextScaleIdx ][ maxGausFilterRadius ][ nextResponseBufferColIdx ];
2527 neighborMaximaDif_2_7 = windowCenterPixelValue - currOctaveBuffersHandler[
2528 nextScaleIdx ][ nextResponseBufferLineIdx ][ prevResponseBufferColIdx];
2529 neighborMaximaDif_2_8 = windowCenterPixelValue - currOctaveBuffersHandler[
2530 nextScaleIdx ][ nextResponseBufferLineIdx ][ windCenterCol ];
2531 neighborMaximaDif_2_9 = windowCenterPixelValue - currOctaveBuffersHandler[
2532 nextScaleIdx ][ nextResponseBufferLineIdx ][ nextResponseBufferColIdx ];
2536 ( neighborMaximaDif_2_1 > 0.0 )
2537 && ( neighborMaximaDif_2_2 > 0.0 )
2538 && ( neighborMaximaDif_2_3 > 0.0 )
2539 && ( neighborMaximaDif_2_4 > 0.0 )
2540 && ( neighborMaximaDif_2_5 > 0.0 )
2541 && ( neighborMaximaDif_2_6 > 0.0 )
2542 && ( neighborMaximaDif_2_7 > 0.0 )
2543 && ( neighborMaximaDif_2_8 > 0.0 )
2544 && ( neighborMaximaDif_2_9 > 0.0 )
2548 ( maskRasterBufferPtr[ 0 ][ windCenterCol ] != 0 )
2555 neighborMaximaDif_0_1
2556 + neighborMaximaDif_0_2
2557 + neighborMaximaDif_0_3
2558 + neighborMaximaDif_0_4
2559 + neighborMaximaDif_0_5
2560 + neighborMaximaDif_0_6
2561 + neighborMaximaDif_0_7
2562 + neighborMaximaDif_0_8
2563 + neighborMaximaDif_1_1
2564 + neighborMaximaDif_1_2
2565 + neighborMaximaDif_1_3
2566 + neighborMaximaDif_1_4
2567 + neighborMaximaDif_1_5
2568 + neighborMaximaDif_1_6
2569 + neighborMaximaDif_1_7
2570 + neighborMaximaDif_1_8
2571 + neighborMaximaDif_1_9
2572 + neighborMaximaDif_2_1
2573 + neighborMaximaDif_2_2
2574 + neighborMaximaDif_2_3
2575 + neighborMaximaDif_2_4
2576 + neighborMaximaDif_2_5
2577 + neighborMaximaDif_2_6
2578 + neighborMaximaDif_2_7
2579 + neighborMaximaDif_2_8
2580 + neighborMaximaDif_2_9;
2582 octaveIdx, scaleIdx );
2584 laplacianSignBufferHandlers[ octaveIdx ][ scaleIdx ][
2585 maxGausFilterRadius ][ windCenterCol ] ;
2587 auxInterestPoint.
m_x = windCenterCol;
2588 auxInterestPoint.
m_y = rasterLine - ( 2 * maxGausFilterRadius) ;
2589 assert( auxInterestPoint.
m_x <
2591 assert( auxInterestPoint.
m_y <
2595 scaleIdx ) < blockMaximas.size() );
2599 currScalePointsSet.insert( auxInterestPoint);
2601 if( currScalePointsSet.size() >
2604 currScalePointsSet.erase( currScalePointsSet.begin() );
2624 for(
unsigned int blockMaximasIdx = 0 ; blockMaximasIdx <
2625 blockMaximas.size() ; ++blockMaximasIdx )
2628 blockMaximas[ blockMaximasIdx ].begin(),
2629 blockMaximas[ blockMaximasIdx ].end() );
2639 const std::string& tifFileName )
2641 std::map<std::string, std::string> rInfo;
2642 rInfo[
"URI"] = tifFileName +
".tif";
2644 std::vector<te::rst::BandProperty*> bandsProperties;
2647 bandsProperties[0]->m_noDataValue = 0;
2656 std::auto_ptr< te::rst::Raster > outputRasterPtr(
2660 unsigned int line = 0;
2661 unsigned int col = 0;
2664 double rasterDataMin = DBL_MAX;
2665 double rasterDataMax = (-1.0) * DBL_MAX;
2668 for( line = 0 ; line < nLines ; ++line )
2669 for( col = 0 ; col < nCols ; ++col )
2671 value = rasterData[ line ][ col ];
2673 if( rasterDataMin > value )
2674 rasterDataMin = value;
2675 if( rasterDataMax < value )
2676 rasterDataMax = value;
2679 if( rasterDataMax == rasterDataMin )
2681 rasterDataMin = 0.0;
2682 rasterDataMax = 1.0;
2685 for( line = 0 ; line < nLines ; ++line )
2686 for( col = 0 ; col < nCols ; ++col )
2688 value = rasterData[ line ][ col ];
2689 value = ( value - rasterDataMin ) / ( rasterDataMax - rasterDataMin );
2691 value = std::max( 0.0, value );
2692 value = std::min( 255.0, value );
2694 outputRasterPtr->setValue( col, line, value, 0 );
2695 outputRasterPtr->setValue( col, line, value, 1 );
2696 outputRasterPtr->setValue( col, line, value, 2 );
2699 InterestPointsSetT::const_iterator itB = interestPoints.begin();
2700 InterestPointsSetT::const_iterator itE = interestPoints.end();
2704 outputRasterPtr->setValue( itB->m_x, itB->m_y, 0, 0 );
2705 outputRasterPtr->setValue( itB->m_x, itB->m_y, 255, 1 );
2706 outputRasterPtr->setValue( itB->m_x, itB->m_y, 0, 2 );
2713 DoublesMatrix& outputData,
const unsigned int iterationsNumber )
2715 if( iterationsNumber == 0 )
return false;
2722 const unsigned int lastLineIndex = nLines - 1;
2723 const unsigned int lastColIndex = nCols - 1;
2724 unsigned int currLine = 0;
2725 unsigned int currCol = 0;
2731 if( iterationsNumber > 1 )
2735 "Cannot allocate image matrix" );
2740 for( currLine = 0 ; currLine < nLines ; ++currLine ) {
2741 outputData( currLine, 0 ) = 0.0;
2742 outputData( currLine, lastColIndex ) = 0.0;
2745 for( currCol = 0 ; currCol < nCols ; ++currCol ) {
2746 outputData( 0, currCol ) = 0.0;
2747 outputData( lastLineIndex, currCol ) = 0.0;
2756 for(
unsigned int iteration = 0 ; iteration < iterationsNumber ;
2759 if( iteration == 0 )
2761 inputPtr = &inputData;
2763 if( iterationsNumber > 1 )
2764 outputPtr = &tempMatrix;
2766 outputPtr = &outputData;
2768 else if( iteration == iterationsNumber - 1 )
2770 inputPtr = outputPtr;
2771 outputPtr = &outputData;
2776 inputPtr = outputPtr;
2780 for( currLine = 1 ; currLine < lastLineIndex ; ++currLine )
2782 for( currCol = 1 ; currCol < lastColIndex ; ++currCol )
2784 outputPtr->operator()( currLine, currCol ) =
2786 inputPtr->operator()( currLine - 1, currCol ) +
2787 ( 4.0 * inputData( currLine, currCol ) ) +
2788 inputPtr->operator()( currLine + 1, currCol ) +
2789 inputPtr->operator()( currLine, currCol - 1 ) +
2790 inputPtr->operator()( currLine, currCol + 1 )
2800 FloatsMatrix& outputData,
const unsigned int iterationsNumber )
2802 if( iterationsNumber == 0 )
2804 outputData = inputData;
2814 const unsigned int lastLineIndex = nLines - 1;
2815 const unsigned int lastColIndex = nCols - 1;
2816 unsigned int currLine = 0;
2817 unsigned int currCol = 0;
2823 if( iterationsNumber > 1 )
2827 "Cannot allocate image matrix" );
2832 for( currLine = 0 ; currLine < nLines ; ++currLine ) {
2833 outputData( currLine, 0 ) = 0.0;
2834 outputData( currLine, lastColIndex ) = 0.0;
2837 for( currCol = 0 ; currCol < nCols ; ++currCol ) {
2838 outputData( 0, currCol ) = 0.0;
2839 outputData( lastLineIndex, currCol ) = 0.0;
2847 float* outputLinePtr = 0;
2848 unsigned int prevLine = 0;
2849 unsigned int prevCol = 0;
2850 unsigned int nextLine = 0;
2851 unsigned int nextCol = 0;
2853 for(
unsigned int iteration = 0 ; iteration < iterationsNumber ;
2856 if( iteration == 0 )
2858 inputPtr = &inputData;
2860 if( iterationsNumber > 1 )
2861 outputPtr = &tempMatrix;
2863 outputPtr = &outputData;
2865 else if( iteration == iterationsNumber - 1 )
2867 inputPtr = outputPtr;
2868 outputPtr = &outputData;
2873 inputPtr = outputPtr;
2879 for( currLine = 1 ; currLine < lastLineIndex ; ++currLine )
2881 prevLine = currLine - 1;
2882 nextLine = currLine + 1;
2884 outputLinePtr = outputPtr->operator[]( currLine );
2886 for( currCol = 1 ; currCol < lastColIndex ; ++currCol )
2888 prevCol = currCol - 1;
2889 nextCol = currCol + 1;
2891 outputLinePtr[ currCol ] =
2893 internalInputMatrix( prevLine, prevCol )
2894 + internalInputMatrix( prevLine, currCol )
2895 + internalInputMatrix( prevLine, nextCol )
2896 + internalInputMatrix( currLine, prevCol )
2897 + internalInputMatrix( currLine, nextCol )
2898 + internalInputMatrix( nextLine, prevCol )
2899 + internalInputMatrix( nextLine, currCol )
2900 + internalInputMatrix( nextLine, nextCol )
2919 unsigned int outCol = 0;
2922 for(
unsigned int outLine = 0 ; outLine < nLines ; ++outLine )
2923 for( outCol = 0; outCol < nCols ; ++outCol )
2925 currSum = inputData[ outLine ][ outCol ];
2928 currSum += outputData[ outLine - 1 ][ outCol ];
2930 currSum += outputData[ outLine ][ outCol - 1 ];
2931 if( outLine && outCol )
2932 currSum -= outputData[ outLine - 1 ][ outCol - 1 ];
2934 outputData[ outLine ][ outCol ] = currSum;
2942 const unsigned int correlationWindowWidth,
2947 validInteresPoints.clear();
2952 const unsigned int rotated90CorralationWindowRadius = (
unsigned int)
2959 ( (
double)correlationWindowWidth )
2961 ( (
double)correlationWindowWidth )
2974 const unsigned int rasterDataLines = rasterData.
getLinesNumber();
2975 const unsigned int firstValidInterestPointX =
2976 rotated90CorralationWindowRadius + 1;
2977 const unsigned int lastValidInterestPointX = rasterDataCols
2978 - rotated90CorralationWindowRadius - 2;
2979 const unsigned int firstValidInterestPointY =
2980 rotated90CorralationWindowRadius + 1;
2981 const unsigned int lastValidInterestPointY = rasterDataLines
2982 - rotated90CorralationWindowRadius - 2;
2985 InterestPointsSetT::const_iterator iPointsIt = interestPoints.begin();
2986 const InterestPointsSetT::const_iterator iPointsItEnd = interestPoints.end();
2988 while( iPointsIt != iPointsItEnd )
2990 if( ( iPointsIt->m_x >= firstValidInterestPointX ) &&
2991 ( iPointsIt->m_x <= lastValidInterestPointX ) &&
2992 ( iPointsIt->m_y >= firstValidInterestPointY ) &&
2993 ( iPointsIt->m_y <= lastValidInterestPointY ) )
2995 validInteresPoints.insert( *iPointsIt );
3005 const unsigned int featureElemsNmb = correlationWindowWidth *
3006 correlationWindowWidth;
3007 const unsigned int featureSizeBytes =
sizeof( float ) *
3011 validInteresPoints.size(), featureElemsNmb ),
3012 "Cannot allocate features matrix" );
3016 boost::scoped_array< float > auxFeatureBufferHandler(
3017 new float[ featureElemsNmb ] );
3018 float* auxFeatureBufferPtr = auxFeatureBufferHandler.get();
3022 unsigned int curr_window_x_start = 0;
3023 unsigned int curr_window_y_start = 0;
3024 unsigned int curr_window_x_center = 0;
3025 unsigned int curr_window_y_center = 0;
3026 unsigned int curr_window_x_end = 0;
3027 unsigned int curr_window_y_end = 0;
3028 const unsigned int wind_radius = correlationWindowWidth / 2;
3029 const float wind_radius_double = (float)wind_radius;
3030 unsigned int curr_x = 0;
3031 unsigned int curr_y = 0;
3032 float curr_x_minus_radius = 0;
3033 float curr_y_minus_radius = 0;
3034 unsigned int curr_offset = 0;
3035 float int_x_dir = 0;
3036 float int_y_dir = 0;
3038 float rotated_curr_x = 0;
3039 float rotated_curr_y = 0;
3042 unsigned int rotated_curr_x_img = 0;
3043 unsigned int rotated_curr_y_img = 0;
3044 float featureElementsNormalizeFactor = 0.0;
3045 unsigned int featureElementIdx = 0;
3046 float* featurePtr = 0;
3047 float featureElementValue = 0.0;
3048 float featureElementMaxValue = 0.0;
3049 float featureElementMinValue = 0.0;
3051 InterestPointsSetT::const_iterator viPointsIt = validInteresPoints.begin();
3052 const InterestPointsSetT::const_iterator viPointsItEnd = validInteresPoints.end();
3053 unsigned int validInteresPointsIndex = 0 ;
3055 while( viPointsIt != viPointsItEnd )
3059 curr_window_x_center = viPointsIt->m_x;
3060 assert( curr_window_x_center >= rotated90CorralationWindowRadius );
3062 rotated90CorralationWindowRadius ) );
3063 curr_window_y_center = viPointsIt->m_y;
3064 assert( curr_window_y_center >= rotated90CorralationWindowRadius );
3065 assert( curr_window_y_center < ( rasterData.
getLinesNumber() - 1 -
3066 rotated90CorralationWindowRadius ) );
3068 curr_window_x_start = curr_window_x_center - wind_radius;
3069 curr_window_y_start = curr_window_y_center - wind_radius;
3070 curr_window_x_end = curr_window_x_start + correlationWindowWidth - 1;
3071 curr_window_y_end = curr_window_y_start + correlationWindowWidth - 1;
3077 for( curr_y = curr_window_y_start ; curr_y <= curr_window_y_end ;
3080 for( curr_offset = 0 ; curr_offset < wind_radius ;
3083 int_x_dir += rasterData( curr_y, curr_window_x_end - curr_offset ) -
3084 rasterData( curr_y, curr_window_x_start + curr_offset );
3092 for( curr_x = curr_window_x_start ; curr_x <= curr_window_x_end ;
3095 for( curr_offset = 0 ; curr_offset < wind_radius ; ++curr_offset )
3097 int_y_dir += rasterData( curr_window_y_start + curr_offset, curr_x ) -
3098 rasterData( curr_window_y_end - curr_offset, curr_x );
3104 int_norm = std::sqrt( ( int_x_dir * int_x_dir ) +
3105 ( int_y_dir * int_y_dir ) );
3107 if( int_norm != 0.0 ) {
3108 rot_cos = int_x_dir / int_norm;
3109 rot_sin = int_y_dir / int_norm;
3116 assert( ( rot_cos >= -1.0 ) && ( rot_cos <= 1.0 ) );
3117 assert( ( rot_sin >= -1.0 ) && ( rot_sin <= 1.0 ) );
3132 memset( auxFeatureBufferPtr, 0, featureSizeBytes );
3133 featureElementIdx = 0;
3134 featureElementMaxValue = -1.0 * FLT_MAX;
3135 featureElementMinValue = FLT_MAX;
3137 for( curr_y = 0 ; curr_y < correlationWindowWidth ; ++curr_y )
3139 for( curr_x = 0 ; curr_x < correlationWindowWidth ; ++curr_x )
3143 curr_x_minus_radius = ((float)curr_x) -
3145 curr_y_minus_radius = ((float)curr_y) -
3151 ( rot_cos * curr_x_minus_radius ) +
3152 ( rot_sin * curr_y_minus_radius );
3155 ( rot_cos * curr_y_minus_radius )
3156 - ( rot_sin * curr_x_minus_radius );
3161 rotated_curr_x += wind_radius_double;
3162 rotated_curr_y += wind_radius_double;
3166 rotated_curr_x_img = curr_window_x_start +
3167 (
unsigned int)
ROUND( rotated_curr_x );
3168 rotated_curr_y_img = curr_window_y_start +
3169 (
unsigned int)
ROUND( rotated_curr_y );
3171 featureElementValue = rasterData( rotated_curr_y_img,
3172 rotated_curr_x_img );
3174 auxFeatureBufferPtr[ featureElementIdx++ ] = featureElementValue;
3176 if( featureElementMaxValue < featureElementValue )
3177 featureElementMaxValue = featureElementValue;
3179 if( featureElementMinValue > featureElementValue )
3180 featureElementMinValue = featureElementValue;
3187 if( featureElementMaxValue == featureElementMinValue )
3188 featureElementsNormalizeFactor = 0.0;
3190 featureElementsNormalizeFactor = 1.0f / ( featureElementMaxValue -
3191 featureElementMinValue );
3193 featurePtr = features[ validInteresPointsIndex ];
3195 for( featureElementIdx = 0 ; featureElementIdx < featureElemsNmb ;
3196 ++featureElementIdx )
3198 featurePtr[ featureElementIdx ] = (
3199 ( auxFeatureBufferPtr[ featureElementIdx ] - featureElementMinValue )
3200 * featureElementsNormalizeFactor );
3201 assert( featurePtr[ featureElementIdx ] >= 0.0 );
3202 assert( featurePtr[ featureElementIdx ] <= 1.0 );
3205 ++validInteresPointsIndex;
3220 validInterestPoints.clear();
3223 InterestPointsSetT::const_iterator iPointsIt = interestPoints.begin();
3224 const InterestPointsSetT::const_iterator iPointsItEnd = interestPoints.end();
3226 while( iPointsIt != iPointsItEnd )
3230 const unsigned int& currIPointCenterX = iPointsIt->m_x;
3231 const unsigned int& currIPointCenterY = iPointsIt->m_y;
3232 const float currIPointScale = 1.2f * iPointsIt->m_feature2 / 9.0f;
3234 unsigned int featureWindowWidth = (
unsigned int)( 20.0 * currIPointScale );
3235 featureWindowWidth += ( ( featureWindowWidth % 2 ) ? 0 : 1 );
3237 const unsigned int feature90DegreeRotatedWindowRadius = (
unsigned int)
3244 ( (
double)featureWindowWidth )
3246 ( (double)featureWindowWidth )
3252 const unsigned int featureElementHaarWindowRadius =
3253 ((
unsigned int)( 2.0 * currIPointScale )) / 2;
3255 const unsigned int currIPointCenterXAllowedMin = featureElementHaarWindowRadius +
3256 feature90DegreeRotatedWindowRadius + 1;
3257 const unsigned int currIPointCenterXAllowedMax = integralRasterData.
getColumnsNumber() -
3258 currIPointCenterXAllowedMin - 1;
3259 const unsigned int currIPointCenterYAllowedMin = currIPointCenterXAllowedMin;
3260 const unsigned int currIPointCenterYAllowedMax = integralRasterData.
getLinesNumber() -
3261 currIPointCenterXAllowedMin - 1;
3263 if( ( currIPointCenterX > currIPointCenterXAllowedMin ) &&
3264 ( currIPointCenterX < currIPointCenterXAllowedMax ) &&
3265 ( currIPointCenterY > currIPointCenterYAllowedMin ) &&
3266 ( currIPointCenterY < currIPointCenterYAllowedMax ) )
3269 validInterestPoints.insert( *iPointsIt );
3277 "Cannot allocate features matrix" );
3281 float auxFeaturesBuffer[ 65 ];
3285 InterestPointsSetT::const_iterator iPointsIt = validInterestPoints.begin();
3286 const InterestPointsSetT::const_iterator iPointsItEnd = validInterestPoints.end();
3287 unsigned int interestPointIdx = 0;
3288 while( iPointsIt != iPointsItEnd )
3292 const unsigned int& currIPointCenterX = iPointsIt->m_x;
3293 const unsigned int& currIPointCenterY = iPointsIt->m_y;
3294 const float currIPointScale = 1.2f * iPointsIt->m_feature2 / 9.0f;
3296 unsigned int featureWindowWidth = (
unsigned int)( 20.0 * currIPointScale );
3297 featureWindowWidth += ( ( featureWindowWidth % 2 ) ? 0 : 1 );
3299 const unsigned int featureWindowRadius = featureWindowWidth / 2;
3300 const float featureWindowRadiusDouble = (float)featureWindowRadius;
3302 const unsigned int featureSubWindowWidth = featureWindowWidth / 4;
3304 const unsigned int featureElementHaarWindowRadius =
3305 ((
unsigned int)( 2.0 * currIPointScale )) / 2;
3307 const unsigned int featureWindowRasterXStart = currIPointCenterX -
3308 featureWindowRadius;
3309 const unsigned int featureWindowRasterYStart = currIPointCenterY -
3310 featureWindowRadius;
3314 unsigned int currentFeaturePtrStartIdx = 0;
3316 for( currentFeaturePtrStartIdx = 0; currentFeaturePtrStartIdx < 65 ;
3317 ++currentFeaturePtrStartIdx )
3318 auxFeaturesBuffer[ currentFeaturePtrStartIdx ] = 0.0;
3322 assert( ((
long int)currIPointCenterX) -
3323 ((
long int)featureWindowRadius) >= 0 );
3324 assert( ((
long int)currIPointCenterY) -
3325 ((
long int)featureWindowRadius) >= 0 );
3326 assert( currIPointCenterX +
3328 assert( currIPointCenterY +
3332 currIPointCenterY, featureWindowRadius );
3334 currIPointCenterY, featureWindowRadius );
3338 const float currIPointRotationNorm = std::sqrt( ( currIPointXIntensity * currIPointXIntensity ) +
3339 ( currIPointYIntensity * currIPointYIntensity ) );
3341 float currIPointRotationSin = 0;
3342 float currIPointRotationCos = 1.0;
3344 if( currIPointRotationNorm != 0.0 )
3346 currIPointRotationCos = currIPointXIntensity / currIPointRotationNorm;
3347 currIPointRotationSin = currIPointYIntensity / currIPointRotationNorm;
3350 assert( ( currIPointRotationCos >= -1.0 ) && ( currIPointRotationCos <= 1.0 ) );
3351 assert( ( currIPointRotationSin >= -1.0 ) && ( currIPointRotationSin <= 1.0 ) );
3369 unsigned int featureWindowYOffset = 0;
3370 unsigned int featureWindowXOffset = 0;
3371 float featureElementZeroCenteredOriginalXIdx = 0;
3372 float featureElementZeroCenteredOriginalYIdx = 0;
3373 float featureElementZeroCenteredRotatedXIdx = 0;
3374 float featureElementZeroCenteredRotatedYIdx = 0;
3375 float featureElementRotatedXIdx = 0;
3376 float featureElementRotatedYIdx = 0;
3377 unsigned int featureElementRasterRotatedXIdx = 0;
3378 unsigned int featureElementRasterRotatedYIdx = 0;
3379 float featureElementOriginalHaarXIntensity = 0;
3380 float featureElementOriginalHaarYIntensity = 0;
3381 float featureElementZeroCenteredOriginalHaarXIntensity = 0;
3382 float featureElementZeroCenteredOriginalHaarYIntensity = 0;
3383 float featureElementRotatedHaarXIntensity = 0;
3384 float featureElementRotatedHaarYIntensity = 0;
3385 float featureElementZeroCenteredRotatedHaarXIntensity = 0;
3386 float featureElementZeroCenteredRotatedHaarYIntensity = 0;
3387 unsigned int featureSubWindowYIdx = 0;
3388 unsigned int featureSubWindowXIdx = 0;
3390 for( featureWindowYOffset = 0 ; featureWindowYOffset < featureWindowWidth ;
3391 featureWindowYOffset += 5 )
3393 featureElementZeroCenteredOriginalYIdx = ((float)featureWindowYOffset)
3394 - featureWindowRadiusDouble;
3396 featureSubWindowYIdx = featureWindowYOffset / featureSubWindowWidth;
3398 for( featureWindowXOffset = 0 ; featureWindowXOffset < featureWindowWidth ;
3399 featureWindowXOffset += 5 )
3401 featureSubWindowXIdx = featureWindowXOffset / featureSubWindowWidth;
3403 currentFeaturePtrStartIdx = ( featureSubWindowYIdx * 4 ) +
3404 featureSubWindowXIdx;
3406 featureElementZeroCenteredOriginalXIdx = ((float)featureWindowXOffset)
3407 - featureWindowRadiusDouble;
3412 featureElementZeroCenteredRotatedXIdx =
3413 ( currIPointRotationCos * featureElementZeroCenteredOriginalXIdx ) +
3414 ( currIPointRotationSin * featureElementZeroCenteredOriginalYIdx );
3415 featureElementZeroCenteredRotatedYIdx =
3416 ( currIPointRotationCos * featureElementZeroCenteredOriginalYIdx )
3417 - ( currIPointRotationSin * featureElementZeroCenteredOriginalXIdx );
3419 featureElementRotatedXIdx = featureElementZeroCenteredRotatedXIdx +
3420 featureWindowRadiusDouble;
3421 featureElementRotatedYIdx = featureElementZeroCenteredRotatedYIdx +
3422 featureWindowRadiusDouble;
3424 featureElementRasterRotatedXIdx = featureWindowRasterXStart +
3425 (
unsigned int)
ROUND( featureElementRotatedXIdx );
3426 featureElementRasterRotatedYIdx = featureWindowRasterYStart +
3427 (
unsigned int)
ROUND( featureElementRotatedYIdx );
3429 assert( ((
long int)featureElementRasterRotatedXIdx) -
3430 ((
long int)featureElementHaarWindowRadius) >= 0 );
3431 assert( ((
long int)featureElementRasterRotatedYIdx) -
3432 ((
long int)featureElementHaarWindowRadius) >= 0 );
3433 assert( featureElementRasterRotatedXIdx +
3435 assert( featureElementRasterRotatedYIdx +
3436 featureElementHaarWindowRadius < integralRasterData.
getLinesNumber() );
3441 featureElementRasterRotatedXIdx, featureElementRasterRotatedYIdx,
3442 featureElementHaarWindowRadius );
3444 featureElementRasterRotatedXIdx, featureElementRasterRotatedYIdx,
3445 featureElementHaarWindowRadius );
3450 featureElementZeroCenteredOriginalHaarXIntensity = featureElementOriginalHaarXIntensity +
3451 featureElementZeroCenteredOriginalXIdx;
3452 featureElementZeroCenteredOriginalHaarYIntensity = featureElementOriginalHaarYIntensity +
3453 featureElementZeroCenteredOriginalYIdx;
3455 featureElementZeroCenteredRotatedHaarXIntensity =
3456 ( currIPointRotationCos * featureElementZeroCenteredOriginalHaarXIntensity ) +
3457 ( currIPointRotationSin * featureElementZeroCenteredOriginalHaarYIntensity );
3458 featureElementZeroCenteredRotatedHaarYIntensity =
3459 ( currIPointRotationCos * featureElementZeroCenteredOriginalHaarYIntensity )
3460 - ( currIPointRotationSin * featureElementZeroCenteredOriginalHaarXIntensity );
3462 featureElementRotatedHaarXIntensity = featureElementZeroCenteredRotatedHaarXIntensity
3463 - featureElementZeroCenteredRotatedXIdx;
3464 featureElementRotatedHaarYIntensity = featureElementZeroCenteredRotatedHaarYIntensity
3465 - featureElementZeroCenteredRotatedYIdx;
3469 assert( currentFeaturePtrStartIdx < 61 );
3471 auxFeaturesBuffer[ currentFeaturePtrStartIdx ] +=
3472 featureElementRotatedHaarXIntensity;
3473 auxFeaturesBuffer[ currentFeaturePtrStartIdx + 1 ] +=
3474 featureElementRotatedHaarYIntensity;
3475 auxFeaturesBuffer[ currentFeaturePtrStartIdx + 2 ] +=
3476 std::abs( featureElementRotatedHaarXIntensity );
3477 auxFeaturesBuffer[ currentFeaturePtrStartIdx + 3 ] +=
3478 std::abs( featureElementRotatedHaarYIntensity );
3484 float* currentFeaturePtr = features[ interestPointIdx ];
3486 float featureElementsNormalizeFactor = 0.0;
3488 for( currentFeaturePtrStartIdx = 0 ; currentFeaturePtrStartIdx < 64 ;
3489 ++currentFeaturePtrStartIdx )
3491 featureElementsNormalizeFactor += ( auxFeaturesBuffer[ currentFeaturePtrStartIdx ]
3492 * auxFeaturesBuffer[ currentFeaturePtrStartIdx ] );
3495 featureElementsNormalizeFactor = std::sqrt( featureElementsNormalizeFactor );
3497 if( featureElementsNormalizeFactor != 0.0 )
3499 featureElementsNormalizeFactor = 1.0f / featureElementsNormalizeFactor;
3502 for( currentFeaturePtrStartIdx = 0 ; currentFeaturePtrStartIdx < 64 ;
3503 ++currentFeaturePtrStartIdx )
3505 currentFeaturePtr[ currentFeaturePtrStartIdx ] = (
3506 auxFeaturesBuffer[ currentFeaturePtrStartIdx ] *
3507 featureElementsNormalizeFactor );
3509 currentFeaturePtr[ currentFeaturePtrStartIdx ] );
3511 currentFeaturePtr[ currentFeaturePtrStartIdx ] );
3518 currentFeaturePtr[ 64 ] = ( iPointsIt->m_feature3 * 64.0f );
3529 const std::string& fileNameBeginning )
3531 const unsigned int tifLinesNumber = (
unsigned int)std::sqrt( (
double)
3535 double const* featureLinePtr = 0;
3537 InterestPointsSetT::const_iterator iIt = interestPoints.begin();
3539 for(
unsigned int featuresIdx = 0 ; featuresIdx < features.
getLinesNumber() ;
3542 featureLinePtr = features[ featuresIdx ];
3544 std::vector<te::rst::BandProperty*> bandsProperties;
3547 bandsProperties[0]->m_noDataValue = 0;
3549 std::map<std::string, std::string> rInfo;
3550 rInfo[
"URI"] = fileNameBeginning +
"_" + boost::lexical_cast< std::string >( iIt->m_x )
3551 +
"_" + boost::lexical_cast< std::string >( iIt->m_y ) +
".tif";
3554 tifLinesNumber, 0, -1 );
3556 std::auto_ptr< te::rst::Raster > outputRasterPtr(
3560 unsigned int line = 0;
3561 unsigned int col = 0;
3567 for( col = 0 ; col < featuresColsNumber ; ++col )
3569 if( min > featureLinePtr[ col ] ) min = featureLinePtr[ col ];
3570 if( max < featureLinePtr[ col ] ) max = featureLinePtr[ col ];
3573 gain = 255.0 / ( max - min );
3575 for( line = 0 ; line < tifLinesNumber ; ++line )
3576 for( col = 0 ; col < tifLinesNumber ; ++col )
3578 value = featureLinePtr[ ( line * tifLinesNumber ) + col ];
3581 value =
MIN( 255.0, value );
3582 value =
MAX( 0.0, value );
3584 outputRasterPtr->setValue( col, line, value, 0 );
3596 const unsigned int maxPt1ToPt2Distance,
3597 const unsigned int enableMultiThread,
3598 const double minAllowedAbsCorrelation,
3601 matchedPoints.clear();
3603 const unsigned int interestPointsSet1Size = interestPointsSet1.size();
3604 if( interestPointsSet1Size == 0 )
return true;
3606 const unsigned int interestPointsSet2Size = interestPointsSet2.size();
3607 if( interestPointsSet2Size == 0 )
return true;
3610 assert( featuresSet1.
getLinesNumber() == interestPointsSet1Size );
3611 assert( featuresSet2.
getLinesNumber() == interestPointsSet2Size );
3615 InterestPointsSetT::const_iterator it1 = interestPointsSet1.begin();
3616 boost::scoped_array< InterestPointT > internalInterestPointsSet1(
3618 for(
unsigned int idx1 = 0 ; idx1 < interestPointsSet1Size ; ++idx1 )
3620 internalInterestPointsSet1[ idx1 ] = *it1;
3625 InterestPointsSetT::const_iterator it2 = interestPointsSet2.begin();
3626 boost::scoped_array< InterestPointT > internalInterestPointsSet2(
3628 for(
unsigned int idx2 = 0 ; idx2 < interestPointsSet2Size ; ++idx2 )
3630 internalInterestPointsSet2[ idx2 ] = *it2;
3640 "Error crearting the correlation matrix" );
3642 unsigned int col = 0;
3643 unsigned int line = 0;
3646 for( line = 0 ; line < interestPointsSet1Size ; ++line )
3648 linePtr = corrMatrix[ line ];
3650 for( col = 0 ; col < interestPointsSet2Size ; ++col )
3656 boost::mutex syncMutex;
3657 unsigned int nextFeatureIdx1ToProcess = 0;
3670 if( enableMultiThread )
3679 boost::thread_group threads;
3681 for(
unsigned int threadIdx = 0 ; threadIdx < procsNumber ;
3684 threads.add_thread(
new boost::thread(
3698 std::vector< float > eachLineMaxABSValues( interestPointsSet1Size,
3700 std::vector< unsigned int > eachLineMaxABSIndexes( interestPointsSet1Size,
3701 interestPointsSet2Size );
3702 std::vector< float > eachColMaxABSValues( interestPointsSet2Size,
3704 std::vector< unsigned int > eachColMaxABSIndexes( interestPointsSet2Size,
3705 interestPointsSet1Size );
3708 for( line = 0 ; line < interestPointsSet1Size ; ++line )
3710 linePtr = corrMatrix[ line ];
3712 for( col = 0 ; col < interestPointsSet2Size ; ++col )
3714 absValue = std::abs( linePtr[ col ] );
3716 if( absValue >= minAllowedAbsCorrelation )
3718 if( absValue > eachLineMaxABSValues[ line ] )
3720 eachLineMaxABSValues[ line ] = absValue;
3721 eachLineMaxABSIndexes[ line ] = col;
3724 if( absValue > eachColMaxABSValues[ col ] )
3726 eachColMaxABSValues[ col ] = absValue;
3727 eachColMaxABSIndexes[ col ] = line;
3737 for( line = 0 ; line < interestPointsSet1Size ; ++line )
3739 col = eachLineMaxABSIndexes[ line ];
3741 if( ( col < interestPointsSet2Size ) &&
3742 ( eachColMaxABSIndexes[ col ] == line ) )
3744 auxMatchedPoints.
m_point1 = internalInterestPointsSet1[ line ];
3745 auxMatchedPoints.
m_point2 = internalInterestPointsSet2[ col ];
3746 auxMatchedPoints.
m_feature = std::abs( corrMatrix( line, col ) );
3748 matchedPoints.insert( auxMatchedPoints );
3768 unsigned int feat2Idx = 0;
3769 float const* feat1Ptr = 0;
3770 float const* feat2Ptr = 0;
3771 float* corrMatrixLinePtr = 0;
3772 unsigned int featCol = 0;
3776 float ccorrelation = 0;
3781 const unsigned int featuresSet1Size =
3783 const unsigned int featuresSet2Size =
3788 std::vector< unsigned int > selectedFeaturesSet2Indexes;
3789 unsigned int selectedFeaturesSet2IndexesSize = 0;
3793 for(
unsigned int feat2Idx = 0 ; feat2Idx < featuresSet2Size ; ++feat2Idx )
3795 interestPointsSet2RTree.
insert(
3806 selectedFeaturesSet2Indexes.resize( featuresSet2Size );
3807 selectedFeaturesSet2IndexesSize = featuresSet2Size;
3808 for(
unsigned int feat2Idx = 0 ; feat2Idx < featuresSet2Size ; ++feat2Idx )
3810 selectedFeaturesSet2Indexes[ feat2Idx ] = feat2Idx;
3816 for(
unsigned int feat1Idx = 0 ; feat1Idx < featuresSet1Size ; ++feat1Idx )
3837 selectedFeaturesSet2Indexes.clear();
3838 interestPointsSet2RTree.
search( auxEnvelope,
3839 selectedFeaturesSet2Indexes );
3841 selectedFeaturesSet2IndexesSize = selectedFeaturesSet2Indexes.size();
3844 corrMatrixLinePtr = paramsPtr->
m_corrMatrixPtr->operator[]( feat1Idx );
3848 for(
unsigned int selectedFSIIdx = 0 ; selectedFSIIdx <
3849 selectedFeaturesSet2IndexesSize ; ++selectedFSIIdx )
3851 feat2Idx = selectedFeaturesSet2Indexes[ selectedFSIIdx ];
3857 for( featCol = 0 ; featCol < featureElementsNmb ; ++featCol )
3859 sumAA += feat1Ptr[ featCol ] * feat1Ptr[ featCol ];
3860 sumBB += feat2Ptr[ featCol ] * feat2Ptr[ featCol ];
3863 cc_norm = std::sqrt( sumAA * sumBB );
3865 if( cc_norm == 0.0 )
3867 corrMatrixLinePtr[ feat2Idx ] = 0;
3872 for( featCol = 0 ; featCol < featureElementsNmb ; ++featCol )
3874 ccorrelation += ( feat1Ptr[ featCol ] * feat2Ptr[ featCol ] ) /
3878 corrMatrixLinePtr[ feat2Idx ] = ccorrelation;
3894 const unsigned int maxPt1ToPt2PixelDistance,
3895 const double maxEuclideanDist,
3896 const unsigned int enableMultiThread,
3899 matchedPoints.clear();
3901 const unsigned int interestPointsSet1Size = interestPointsSet1.size();
3902 if( interestPointsSet1Size == 0 )
return true;
3904 const unsigned int interestPointsSet2Size = interestPointsSet2.size();
3905 if( interestPointsSet2Size == 0 )
return true;
3908 assert( featuresSet1.
getLinesNumber() == interestPointsSet1Size );
3909 assert( featuresSet2.
getLinesNumber() == interestPointsSet2Size );
3913 InterestPointsSetT::const_iterator it1 = interestPointsSet1.begin();
3914 boost::scoped_array< InterestPointT > internalInterestPointsSet1(
3916 for(
unsigned int idx1 = 0 ; idx1 < interestPointsSet1Size ; ++idx1 )
3918 internalInterestPointsSet1[ idx1 ] = *it1;
3922 InterestPointsSetT::const_iterator it2 = interestPointsSet2.begin();
3923 boost::scoped_array< InterestPointT > internalInterestPointsSet2(
3925 for(
unsigned int idx2 = 0 ; idx2 < interestPointsSet2Size ; ++idx2 )
3927 internalInterestPointsSet2[ idx2 ] = *it2;
3936 "Error crearting the correlation matrix" );
3938 unsigned int col = 0;
3939 unsigned int line = 0;
3942 for( line = 0 ; line < interestPointsSet1Size ; ++line )
3944 linePtr = distMatrix[ line ];
3946 for( col = 0 ; col < interestPointsSet2Size ; ++col )
3948 linePtr[ col ] = FLT_MAX;
3952 boost::mutex syncMutex;
3953 unsigned int nextFeatureIdx1ToProcess = 0;
3965 if( enableMultiThread )
3974 boost::thread_group threads;
3976 for(
unsigned int threadIdx = 0 ; threadIdx < procsNumber ;
3979 threads.add_thread(
new boost::thread(
3993 std::vector< float > eachLineMinValues( interestPointsSet1Size,
3995 std::vector< unsigned int > eachLineMinIndexes( interestPointsSet1Size,
3996 interestPointsSet2Size );
3997 std::vector< float > eachColMinValues( interestPointsSet2Size,
3999 std::vector< unsigned int > eachColMinIndexes( interestPointsSet2Size,
4000 interestPointsSet1Size );
4001 float maxDistValue = FLT_MAX * (-1.0);
4003 for( line = 0 ; line < interestPointsSet1Size ; ++line )
4005 linePtr = distMatrix[ line ];
4007 for( col = 0 ; col < interestPointsSet2Size ; ++col )
4009 const float& value = linePtr[ col ];
4011 if( value <= maxEuclideanDist )
4013 if( value < eachLineMinValues[ line ] )
4015 eachLineMinValues[ line ] = value;
4016 eachLineMinIndexes[ line ] = col;
4019 if( value < eachColMinValues[ col ] )
4021 eachColMinValues[ col ] = value;
4022 eachColMinIndexes[ col ] = line;
4025 if( value > maxDistValue ) maxDistValue = value;
4030 if( maxDistValue == 0.0 ) maxDistValue = 1.0;
4036 for( line = 0 ; line < interestPointsSet1Size ; ++line )
4038 col = eachLineMinIndexes[ line ];
4040 if( ( col < interestPointsSet2Size ) &&
4041 ( eachColMinIndexes[ col ] == line ) )
4043 const float& distValue = distMatrix( line, col );
4045 auxMatchedPoints.
m_point1 = internalInterestPointsSet1[ line ];
4046 auxMatchedPoints.
m_point2 = internalInterestPointsSet2[ col ],
4047 auxMatchedPoints.
m_feature = ( maxDistValue - distValue ) /
4050 matchedPoints.insert( auxMatchedPoints );
4072 unsigned int feat2Idx = 0;
4073 float const* feat1Ptr = 0;
4074 float const* feat2Ptr = 0;
4075 float* corrMatrixLinePtr = 0;
4076 unsigned int featCol = 0;
4079 float euclideanDist = 0;
4083 const unsigned int featuresSet1Size =
4085 const unsigned int featuresSet2Size =
4090 std::vector< unsigned int > selectedFeaturesSet2Indexes;
4091 unsigned int selectedFeaturesSet2IndexesSize = 0;
4095 for(
unsigned int feat2Idx = 0 ; feat2Idx < featuresSet2Size ; ++feat2Idx )
4097 interestPointsSet2RTree.
insert(
4108 selectedFeaturesSet2Indexes.resize( featuresSet2Size );
4109 selectedFeaturesSet2IndexesSize = featuresSet2Size;
4110 for(
unsigned int feat2Idx = 0 ; feat2Idx < featuresSet2Size ; ++feat2Idx )
4112 selectedFeaturesSet2Indexes[ feat2Idx ] = feat2Idx;
4118 for(
unsigned int feat1Idx = 0 ; feat1Idx < featuresSet1Size ; ++feat1Idx )
4139 selectedFeaturesSet2Indexes.clear();
4140 interestPointsSet2RTree.
search( auxEnvelope,
4141 selectedFeaturesSet2Indexes );
4143 selectedFeaturesSet2IndexesSize = selectedFeaturesSet2Indexes.size();
4146 corrMatrixLinePtr = paramsPtr->
m_distMatrixPtr->operator[]( feat1Idx );
4150 for(
unsigned int selectedFSIIdx = 0 ; selectedFSIIdx <
4151 selectedFeaturesSet2IndexesSize ; ++selectedFSIIdx )
4153 feat2Idx = selectedFeaturesSet2Indexes[ selectedFSIIdx ];
4157 euclideanDist = 0.0;
4159 for( featCol = 0 ; featCol < featureElementsNmb ; ++featCol )
4161 diff = feat1Ptr[ featCol ] - feat2Ptr[ featCol ];
4162 euclideanDist += ( diff * diff );
4165 euclideanDist = std::sqrt( euclideanDist );
4167 corrMatrixLinePtr[ feat2Idx ] = euclideanDist;
4178 const unsigned int nCols )
4180 std::cout << std::endl;
4182 for(
unsigned int line = 0 ; line < nLines ; ++line )
4184 std::cout << std::endl <<
"[";
4186 for(
unsigned int col = 0 ; col < nCols ; ++col )
4188 std::cout <<
" " << buffer[ line ][ col ];
4194 std::cout << std::endl;
static float getSurfDyyDerivative(float **bufferPtr, const unsigned int ¢erX, const unsigned int ¢erY, const unsigned int &lobeWidth, const unsigned int &lobeRadius)
Return a SURF box filter Dxx derivative centered over the given position from the given integral imag...
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
double m_moravecMinAbsCorrelation
The minimum acceptable absolute correlation value when matching features (when applicable), default:0.5, valid range: [0,1].
unsigned int m_moravecGaussianFilterIterations
The number of noise Gaussin iterations, when applicable (used to remove image noise, zero will disable the Gaussian Filter, default:1).
unsigned int m_moravecCorrelationWindowWidth
The correlation window width used to correlate points between the images (minimum 3...
#define TERP_DEBUG_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
unsigned int m_maxInterestPointsPerRasterLinesBlock
The maximum number of points to find for each raster lines block.
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
unsigned int m_y
Point Y coord.
const OutputParameters & operator=(const OutputParameters ¶ms)
bool m_enableProgress
Enable/Disable the progress interface (default:false).
static unsigned int getSurfFilterSize(const unsigned int &octaveIndex, const unsigned int &scaleIndex)
Return the surf octave filter size (width).
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
static bool generateSurfFeatures(const InterestPointsSetT &interestPoints, const FloatsMatrix &integralRasterData, InterestPointsSetT &validInterestPoints, FloatsMatrix &features)
Generate a Surf features matrix for the given interes points.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
unsigned int m_maxInterestPointsPerRasterLinesBlock
The maximum number of points to find for each raster lines block for each scale.
FloatsMatrix const * m_featuresSet2Ptr
InterestPointT const * m_interestPointsSet1Ptr
bool executeSurf(const double raster1XRescFact, const double raster1YRescFact, const double raster2XRescFact, const double raster2YRescFact, te::common::TaskProgress *progressPtr, TiePointsLocator::OutputParameters *outParamsPtr, std::vector< double > &tiePointsWeights)
Executes the SURF algorithm using the supplied parameters.
Blue channel color interpretation.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
static float getSurfDxxDerivative(float **bufferPtr, const unsigned int ¢erX, const unsigned int ¢erY, const unsigned int &lobeWidth, const unsigned int &lobeRadius)
Return a SURF box filter Dyy derivative centered over the given position from the given integral imag...
FloatsMatrix const * m_featuresSet1Ptr
InterestPointsSetT * m_interestPointsPtr
A pointer to a valid interest points container.
te::rst::Raster const * m_inMaskRaster2Ptr
Optional one band input mask raster 2 (tie-points will not be generated inside mask image areas marke...
bool locateSurfInterestPoints(const FloatsMatrix &integralRasterData, UCharsMatrix const *maskRasterDataPtr, InterestPointsSetT &interestPoints) const
SURF interest points locator.
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.
unsigned int m_moravecWindowWidth
The Moravec window width used to locate canditate tie-points (minimum 3, default: 5 )...
void clear()
Clear all allocated resources and go back to the initial default parameters.
unsigned int m_raster2TargetAreaWidth
The raster 2 target area width (default:0 - The entire raster will be considered).
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
TiePointsLocator locator.
std::auto_ptr< te::gm::GeometricTransformation > m_transformationPtr
The generated geometric transformation with the base mininum required tie-points set ( depending on t...
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
unsigned int m_x
Point X coord.
InterestPointT m_point2
Interest point 2.
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
FloatsMatrix const * m_integralRasterDataPtr
The integral image raster data.
static bool applyMeanFilter(const FloatsMatrix &inputData, FloatsMatrix &outputData, const unsigned int iterationsNumber)
Mean Filter.
bool m_enableGeometryFilter
Enable/disable the geometry filter/outliers remotion (default:true).
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
static Raster * make()
It creates and returns an empty raster with default raster driver.
float m_feature3
Interest point feature 3 value.
unsigned int getLinesNumber() const
The number of current matrix lines.
unsigned int m_maxPt1ToPt2Distance
Zero (disabled) or the maximum distance between a point from set 1 to a point from set 1 (points beyo...
A class that represents an R-tree.
static bool locateMoravecInterestPoints(const FloatsMatrix &rasterData, UCharsMatrix const *maskRasterDataPtr, const unsigned int moravecWindowWidth, const unsigned int maxInterestPoints, const unsigned int enableMultiThread, InterestPointsSetT &interestPoints)
Moravec interest points locator.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
static float getHaarYVectorIntensity(BufferType &buffer, const unsigned int ¢erX, const unsigned int ¢erY, const unsigned int &radius)
Return a Haar Y intesity vector for the window centered at the given point.
InterestPointsSetT * m_interestPointsPtr
A pointer to a valid interest points container.
unsigned int GetPhysProcNumber()
Returns the number of physical processors.
unsigned int m_scalesNumber
Thread return value pointer.
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
unsigned int m_maxPt1ToPt2Distance
Zero (disabled) or the maximum distance between a point from set 1 to a point from set 1 (points beyo...
unsigned int * m_nextFeatureIdx1ToProcessPtr
boost::mutex * m_syncMutexPtr
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
unsigned int m_maxRasterLinesBlockMaxSize
The maximum lines number of each raster block to process.
static GeometricTransformation * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
static bool generateCorrelationFeatures(const InterestPointsSetT &interestPoints, const unsigned int correlationWindowWidth, const FloatsMatrix &rasterData, FloatsMatrix &features, InterestPointsSetT &validInteresPoints)
Generate correlation features ( normalized - unit vector ) matrix for the given interes points...
static bool createIntegralImage(const FloatsMatrix &inputData, FloatsMatrix &outputData)
Create an integral image.
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
The parameters passed to the executeMatchingByEuclideanDistThreadEntry method.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
const InputParameters & operator=(const InputParameters ¶ms)
static void features2Tiff(const DoublesMatrix &features, const InterestPointsSetT &interestPoints, const std::string &fileNameBeginning)
Save the generated features to tif files.
double m_geomTransfMaxError
The maximum allowed transformation error (pixel units, default:2).
Method
Allowed interpolation methods.
std::multiset< InterestPointT > InterestPointsSetT
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.
double m_pixelSizeXRelation
The pixel resolution relation m_pixelSizeXRelation = raster1_pixel_res_x / raster2_pixel_res_x (defau...
static void printBuffer(double **buffer, const unsigned int nLines, const unsigned int nCols)
Print the given buffer to std::out.
Red channel color interpretation.
2D Geometric transformation tie-points filter (outliers remotion).
Abstract parameters base interface.
std::vector< TiePoint > m_tiePoints
Tie points.
static const factory_type * find(const std::string &factoryKey)
A rectified grid is the spatial support for raster data.
A raster band description.
TiePointsLocator input parameters.
static bool loadRasterData(te::rst::Raster const *rasterPtr, const std::vector< unsigned int > &rasterBands, te::rst::Raster const *maskRasterPtr, const unsigned int maskRasterBand, const unsigned int rasterTargetAreaLineStart, const unsigned int rasterTargetAreaColStart, const unsigned int rasterTargetAreaWidth, const unsigned int rasterTargetAreaHeight, const double rescaleFactorX, const double rescaleFactorY, const te::rst::Interpolator::Method rasterInterpMethod, const unsigned char maxMemPercentUsage, std::vector< boost::shared_ptr< FloatsMatrix > > &loadedRasterData, UCharsMatrix &loadedMaskRasterData)
Load rasters data (normalized between 0 and 1).
double m_lly
Lower left corner y-coordinate.
InterestPointT m_point1
Interest point 1.
FloatsMatrix const * m_featuresSet2Ptr
static void locateSurfInterestPointsThreadEntry(SurfLocatorThreadParams *paramsPtr)
Surf locator thread entry.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
bool applyRansac(const std::string &transfName, const GTParameters &inputParams, const double maxDirectMapError, const double maxInverseMapError, const RansacItCounterT &maxIterations, const double &assurance, const bool enableMultiThread, const std::vector< double > &tiePointsWeights, std::vector< te::gm::GTParameters::TiePoint > &outTiePoints, std::auto_ptr< GeometricTransformation > &outTransf)
Apply a RANSAC based outliers remotion strategy.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
double m_ury
Upper right corner y-coordinate.
unsigned int m_maxR1ToR2Offset
The maximum offset (pixels units) between a raster 1 point end the respective raster 2 point (default...
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
float m_feature
Matched interest feature.
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
TemplateElementType ElementTypeT
Public matrix element type definition.
unsigned int m_surfOctavesNumber
The number of octaves to generate, when applicable (default: 3, minimum:1).
float m_feature2
Interest point feature 2 value.
double m_urx
Upper right corner x-coordinate.
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
#define ROUND(x)
Minimum of two values.
FloatsMatrix * m_corrMatrixPtr
unsigned int m_octavesNumber
The number of octaves to generate (minimum:1).
unsigned int m_moravecWindowWidth
Thread return value pointer.
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
AbstractParameters * clone() const
Create a clone copy of this instance.
InterestPointT const * m_interestPointsSet1Ptr
static float getHaarXVectorIntensity(BufferType &buffer, const unsigned int ¢erX, const unsigned int ¢erY, const unsigned int &radius)
Return a Haar X intesity vector for the window centered at the given point.
unsigned long int GetTotalPhysicalMemory()
Returns the amount of total physical memory (bytes).
bool executeMoravec(const double raster1XRescFact, const double raster1YRescFact, const double raster2XRescFact, const double raster2YRescFact, te::common::TaskProgress *progressPtr, TiePointsLocator::OutputParameters *outParamsPtr, std::vector< double > &tiePointsWeights)
Executes the Moravec algorithm using the supplied parameters.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
const Algorithm & operator=(const Algorithm &)
InteresPointsLocationStrategyType m_interesPointsLocationStrategy
The strategy used to locate interest points (default:SurfStrategyT).
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
static void executeMatchingByEuclideanDistThreadEntry(ExecuteMatchingByEuclideanDistThreadEntryParams *paramsPtr)
Correlation/Euclidean match thread entry.
static void roolUpBuffer(BufferElementT **bufferPtr, const unsigned int &bufferLinesNumber)
RoolUp a buffer of lines.
A raster band description.
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
The parameters passed to the matchCorrelationEuclideanThreadEntry method.
#define MIN(a, b)
Macro that returns min between two values.
A generic template matrix.
double m_geometryFilterAssurance
Geometry assurance (the error-free selection percent assurance) - valid range (0-1) - default:0...
The parameters passed to the surfLocatorThreadEntry method.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
float m_feature1
Interest point feature 1 value.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
boost::mutex * m_syncMutexPtr
unsigned int getColumnsNumber() const
The number of current matrix columns.
double m_pixelSizeYRelation
The pixel resolution relation m_pixelSizeYRelation = raster1_pixel_res_y / raster2_pixel_res_y (defau...
double m_surfMaxNormEuclideanDist
The maximum acceptable euclidean distance when matching features (when applicable), default:0.5, valid range: [0,1].
static bool executeMatchingByEuclideanDist(const FloatsMatrix &featuresSet1, const FloatsMatrix &featuresSet2, const InterestPointsSetT &interestPointsSet1, const InterestPointsSetT &interestPointsSet2, const unsigned int maxPt1ToPt2PixelDistance, const double maxEuclideanDist, const unsigned int enableMultiThread, MatchedInterestPointsSetT &matchedPoints)
Match each feature using eucliean distance.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
te::rst::Raster const * m_inMaskRaster1Ptr
Optional one band input mask raster 1 (tie-points will not be generated inside mask image areas marke...
Raster Processing algorithm output parameters base interface.
double m_llx
Lower left corner x-coordinate.
static bool executeMatchingByCorrelation(const FloatsMatrix &featuresSet1, const FloatsMatrix &featuresSet2, const InterestPointsSetT &interestPointsSet1, const InterestPointsSetT &interestPointsSet2, const unsigned int maxPt1ToPt2PixelDistance, const unsigned int enableMultiThread, const double minAllowedAbsCorrelation, MatchedInterestPointsSetT &matchedPoints)
Match each feature using correlation.
static void locateMoravecInterestPointsThreadEntry(MoravecLocatorThreadParams *paramsPtr)
Movavec locator thread entry.
void reset()
Reset (clear) the active instance data.
An abstract class for raster data strucutures.
unsigned int * m_nextFeatureIdx1ToProcessPtr
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
This class can be used to inform the progress of a task.
unsigned int m_raster1TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
unsigned int m_maxRasterLinesBlockMaxSize
The maximum lines number of each raster block to process.
#define TERP_LOG_AND_THROW(message)
Logs a error message and throws.
unsigned long int GetUsedVirtualMemory()
Returns the amount of used virtual memory (bytes) for the current process (physical + swapped)...
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
unsigned long int GetTotalVirtualMemory()
Returns the amount of total virtual memory (bytes) that can be claimed by the current process (physic...
static float getSurfDxyDerivative(float **bufferPtr, const unsigned int ¢erX, const unsigned int ¢erY, const unsigned int &lobeWidth)
Return a SURF box filter Dxy derivative centered over the given position from the given integral imag...
unsigned int m_raster1TargetAreaWidth
The raster 1 target area width (default:0 - The entire raster will be considered).
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
2D Geometric transformation parameters.
AbstractParameters * clone() const
Create a clone copy of this instance.
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
InterestPointT const * m_interestPointsSet2Ptr
unsigned int m_maxTiePoints
The maximum number of tie-points to generate (default=0 - Automatically found).
An Envelope defines a 2D rectangular region.
Near neighborhood interpolation method.
InterestPointT const * m_interestPointsSet2Ptr
unsigned int m_surfScalesNumber
The number of sub-sampling scales to generate, when applicable (default:4, minimum:3).
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
MemoryPolicy getMemPolicy() const
Returns the current memory policy.
double m_rastersRescaleFactor
Global rescale factor to apply to all input rasters (default:1, valid range: non-zero positive values...
Green channel color interpretation.
#define MAX(a, b)
Macro that returns max between two values.
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
The parameters passed to the moravecLocatorThreadEntry method.
FloatsMatrix const * m_rasterDataPtr
The loaded raster data.
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
FloatsMatrix const * m_featuresSet1Ptr
FloatsMatrix * m_distMatrixPtr
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
static void createTifFromMatrix(const DoublesMatrix &rasterData, const InterestPointsSetT &interestPoints, const std::string &tifFileName)
Moravec interest points locator.
static bool applyGaussianFilter(const DoublesMatrix &inputData, DoublesMatrix &outputData, const unsigned int iterationsNumber)
Gaussian Filter.
TiePointsLocator::InputParameters m_inputParameters
TiePointsLocator input execution parameters.
Raster Processing algorithm input parameters base interface.
bool m_isInitialized
Tells if this instance is initialized.
TiePointsLocator output parameters.
static void executeMatchingByCorrelationThreadEntry(ExecuteMatchingByCorrelationThreadEntryParams *paramsPtr)
Correlation/Euclidean match thread entry.