29 #include "../raster/BandProperty.h"
30 #include "../raster/RasterFactory.h"
31 #include "../raster/Band.h"
32 #include "../raster/Grid.h"
33 #include "../geometry/Envelope.h"
34 #include "../common/progress/TaskProgress.h"
35 #include "../memory/ExpansibleRaster.h"
63 m_lowResRasterPtr = 0;
64 m_lowResRasterBands.clear();
65 m_highResRasterPtr = 0;
66 m_highResRasterBand = 0;
67 m_enableProgress =
false;
68 m_enableThreadedProcessing =
true;
113 m_outputRasterPtr.reset();
142 throw( te::rp::Exception )
152 std::auto_ptr< te::common::TaskProgress > progressPtr;
157 progressPtr->setTotalSteps( 4 );
159 progressPtr->setMessage(
"Fusing images" );
164 std::auto_ptr< te::rst::Raster > ressampledRasterPtr;
167 "Ressampled raster data loading error" );
173 progressPtr->pulse();
174 if( ! progressPtr->isActive() )
return false;
179 std::auto_ptr< te::rst::Raster > pcaRasterPtr;
180 boost::numeric::ublas::matrix< double > pcaMatrix;
184 std::vector< te::rst::BandProperty * > bandProperties;
185 std::vector< unsigned int > ressampledRasterBands;
187 for(
unsigned int bandIdx = 0 ; bandIdx <
188 ressampledRasterPtr->getNumberOfBands() ; ++bandIdx )
191 *ressampledRasterPtr->getBand( bandIdx )->getProperty() ) );
194 ressampledRasterBands.push_back( bandIdx );
208 ressampledRasterBands, pcaMatrix, *pcaRasterPtr, ressampledRasterBands,
210 "Principal components generation error" );
217 progressPtr->pulse();
218 if( ! progressPtr->isActive() )
return false;
230 progressPtr->pulse();
231 if( ! progressPtr->isActive() )
return false;
239 std::vector< te::rst::BandProperty * > bandProperties;
240 std::vector< unsigned int > outputRasterBands;
242 for(
unsigned int bandIdx = 0 ; bandIdx <
243 pcaRasterPtr->getNumberOfBands() ; ++bandIdx )
246 *pcaRasterPtr->getBand( bandIdx )->getProperty() ) );
247 bandProperties[ bandIdx ]->m_type =
248 ressampledRasterPtr->getBand( bandIdx )->getProperty()->m_type;
250 outputRasterBands.push_back( bandIdx );
262 "Output raster creation error" );
267 "Inverse PCA error" );
272 progressPtr->pulse();
273 if( ! progressPtr->isActive() )
return false;
286 throw( te::rp::Exception )
299 "Invalid low Resolution Raster Pointer" )
305 for(
unsigned int lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
311 "Invalid raster band" );
317 "Invalid high resolution Raster Pointer" )
326 "Invalid raster band" );
344 unsigned int lowResRasterBandsIdx = 0;
345 unsigned int lowResRasterBandIdx = 0;
351 std::vector< te::rst::BandProperty * > ressampledBandProperties;
353 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
360 ressampledBandProperties[ lowResRasterBandsIdx ]->m_blkw = outNCols;
361 ressampledBandProperties[ lowResRasterBandsIdx ]->m_blkh = 1;
362 ressampledBandProperties[ lowResRasterBandsIdx ]->m_nblocksx = 1;
363 ressampledBandProperties[ lowResRasterBandsIdx ]->m_nblocksy = outNRows;
369 ressampledBandProperties ) );
376 const double colsRescaleFactor =
379 const double rowsRescaleFactor =
382 unsigned int outRow = 0;
383 unsigned int outCol = 0;
388 std::complex< double > value = 0;
390 double inNoDataValue = 0;
391 double outNoDataValue = 0;
393 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
400 for( outRow = 0 ; outRow < outNRows ; ++outRow )
402 inRow = ((double)outRow) * rowsRescaleFactor;
404 for( outCol = 0 ; outCol < outNCols ; ++outCol )
406 inCol = ((double)outCol) * colsRescaleFactor;
408 interpol.
getValue( inCol, inRow, value, lowResRasterBandIdx );
410 if( value.real() == inNoDataValue )
412 ressampledRaster.
setValue( outCol, outRow, outNoDataValue, lowResRasterBandsIdx );
416 ressampledRaster.
setValue( outCol, outRow, value.real(), lowResRasterBandsIdx );
434 double pcaZeroMean = 0.0;
436 0 : 1, pcaZeroMean ) )
441 double pcaZeroStdDev = 0.0;
443 0 : 1, &pcaZeroMean, pcaZeroStdDev ) )
454 double hrStdDev = 0.0;
460 const double gain = ( ( hrStdDev == 0.0 ) ? 0.0 : ( pcaZeroStdDev / hrStdDev ) );
465 unsigned int col = 0;
466 unsigned int row = 0;
468 double pcaAllowedMin = 0;
469 double pcaAllowedMax = 0;
473 for( row = 0 ; row < nRows ; ++row )
475 for( col = 0 ; col < nCols ; ++col )
478 if( value == hrNoDataValue )
480 pcaBand.setValue( col, row, pcaNoDataValue );
484 value = ( ( value - hrMean ) * gain ) + pcaZeroMean;
485 value = std::max( pcaAllowedMin, value );
486 value = std::min( pcaAllowedMax, value );
488 pcaBand.setValue( col, row, value );
bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
Near neighborhood interpolation method.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
bool swapBandByHighResRaster(te::rst::Raster &pcaRaster, const unsigned int pcaRasterBandIdx)
Swap the band values by the normalized high resolution raster data.
A raster band description.
AbstractParameters * clone() const
Create a clone copy of this instance.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
virtual const char * what() const
It outputs the exception message.
bool m_isInitialized
Tells if this instance is initialized.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
void TERPEXPORT GetDataTypeRange(const int dataType, double &min, double &max)
Returns the real data type range (all values that can be represented by the given data type)...
This class can be used to inform the progress of a task.
Raster Processing algorithm output parameters base interface.
PCAFusion output parameters.
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
bool DirectPrincipalComponents(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &pcaRaster, const std::vector< unsigned int > &pcaRasterBands, const unsigned int maxThreads)
Generate all principal components from the given input raster.
Raster Processing functions.
#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...
const Algorithm & operator=(const Algorithm &)
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
BandProperty * getProperty()
Returns the band property.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
A raster band description.
Grid * getGrid()
It returns the raster grid.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Abstract parameters base interface.
int getSRID() const
Returns the raster spatial reference system identifier.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
InputParameters m_inputParameters
Input execution parameters.
bool loadRessampledRaster(std::auto_ptr< te::rst::Raster > &ressampledRasterPtr) const
Load resampled data from the input image.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
static Raster * make()
It creates and returns an empty raster with default raster driver.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
bool InversePrincipalComponents(const te::rst::Raster &pcaRaster, const boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
A rectified grid is the spatial support for raster data.
Creation of skeleton imagems.
bool GetStdDevValue(const te::rst::Band &band, const unsigned int maxThreads, double const *const meanValuePtr, double &stdDevValue)
Get the standard deviation of band pixel values.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
const OutputParameters & operator=(const OutputParameters ¶ms)