29 #include "../raster/Raster.h"
30 #include "../raster/Band.h"
31 #include "../raster/BandIterator.h"
32 #include "../raster/BandProperty.h"
33 #include "../raster/RasterProperty.h"
34 #include "../raster/RasterSummaryManager.h"
35 #include "../raster/RasterFactory.h"
36 #include "../common/progress/TaskProgress.h"
40 #include <boost/concept_check.hpp>
62 m_hECMaxInput.clear();
63 m_sMASCMeanInput.clear();
64 m_sMASCStdInput.clear();
67 m_inRasterBands.clear();
68 m_enableProgress =
false;
114 m_createdOutRasterPtr.reset();
115 m_outRasterBands.clear();
116 m_createdOutRasterDSType.clear();
117 m_createdOutRasterInfo.clear();
148 throw( te::rp::Exception )
162 std::vector< te::rst::BandProperty* > bandsProperties;
163 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
186 "Output raster creation error" );
199 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
205 "Invalid output raster band" )
249 throw( te::rp::Exception )
258 "Invalid raster pointer" );
264 "Invalid bands number" );
266 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
272 "Invalid input raster band" );
277 switch( inputParamsPtr->
m_type )
283 "Invalid parameter m_lCMinInput" );
286 "Invalid parameter m_lCMaxInput" );
294 "Invalid parameter m_hECMaxInput" );
302 "Invalid parameter m_sMASCMeanInput" );
305 "Invalid parameter m_sMASCStdInput" );
333 std::auto_ptr< te::common::TaskProgress > progressPtr;
334 if( enableGlobalProgress )
337 progressPtr->setMessage(
"Contrast" );
341 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
349 double outRangeMin = 0.0;
350 double outRangeMax = 0.0;
352 outRangeMin, outRangeMax );
353 const double outRasterRange = outRangeMax - outRangeMin;
358 if( ( outRasterRange != 0.0 ) && ( inRasterRange != 0.0 ) )
366 (!enableGlobalProgress) ) )
371 if( enableGlobalProgress )
373 progressPtr->pulse();
374 if( ! progressPtr->isActive() )
return false;
395 std::auto_ptr< te::common::TaskProgress > progressPtr;
399 progressPtr->setMessage(
"Contrast" );
405 const double lutfactor =
414 double outRangeMin = 0.0;
415 double outRangeMax = 0.0;
417 outRangeMin, outRangeMax );
424 std::map<double, double> lut;
425 const double minp = rsummary->at(niband).m_minVal->real();
426 const double maxp = rsummary->at(niband).m_maxVal->real();
427 for (
double pixel = minp; pixel <= maxp; pixel++)
430 for (
double nj = minp; nj <= pixel; nj++)
431 newvalue += rsummary->at(niband).m_histogramR->operator[](nj);
432 lut[pixel] = lutfactor * newvalue;
435 while (ibandit != ibanditend)
437 value = lut[ *ibandit ];
438 value = std::max( outRangeMin, value );
439 value = std::min( outRangeMax, value );
440 oband->
setValue(ibandit.getColumn(), ibandit.getRow(), value);
446 progressPtr->pulse();
447 if( ! progressPtr->isActive() )
return false;
464 std::auto_ptr< te::common::TaskProgress > progressPtr;
468 progressPtr->setMessage(
"Contrast" );
481 double outRangeMin = 0.0;
482 double outRangeMax = 0.0;
484 outRangeMin, outRangeMax );
491 const double meanp = rsummary->at(niband).m_meanVal->real();
492 const double stdp = rsummary->at(niband).m_stdVal->real();
506 newvalue = (value - meanp) * c1 + c2;
507 newvalue = std::max( outRangeMin, newvalue );
508 newvalue = std::min( outRangeMax, newvalue );
514 progressPtr->pulse();
515 if( ! progressPtr->isActive() )
return false;
525 const bool enableProgress )
531 double outRangeMin = 0.0;
532 double outRangeMax = 0.0;
534 outRangeMin, outRangeMax );
536 std::auto_ptr< te::common::TaskProgress > progressPtr;
540 progressPtr->setMessage(
"Contrast" );
543 if( ( inBlkWidthPixels == outBlkWidthPixels ) &&
544 ( inBlkHeightPixels == outBlkHeightPixels ) )
546 const unsigned int blockSizePixels = inBlkWidthPixels *
550 unsigned char* inputBuffer =
new unsigned char[ inRasterBand.
getBlockSize() ];
551 unsigned char* outputBuffer =
new unsigned char[ outRasterBand.
getBlockSize() ];
552 double* inDoublesBuffer =
new double[ blockSizePixels ];
553 double* outDoublesBuffer =
new double[ blockSizePixels ];
556 unsigned int blockXIndex = 0;
557 unsigned int blockOffset = 0;
560 if( enableProgress ) progressPtr->setTotalSteps( yBlocksNmb * xBlocksNmb );
562 for(
unsigned int blockYIndex = 0 ; blockYIndex < yBlocksNmb ;
565 for( blockXIndex = 0 ; blockXIndex < xBlocksNmb ;
568 inRasterBand.
read( blockXIndex, blockYIndex, inputBuffer );
571 blockSizePixels, inDoublesBuffer );
573 for( blockOffset = 0 ; blockOffset < blockSizePixels ; ++blockOffset )
575 (this->*remapFuncPtr)( inDoublesBuffer[blockOffset],
577 outDoublesBuffer[blockOffset] = std::max( outRangeMin, std::min(
578 outRangeMax, outValue ) );
582 outputVectorDataType, outputBuffer );
584 outRasterBand.
write( blockXIndex, blockYIndex, outputBuffer );
588 progressPtr->pulse();
589 if( ! progressPtr->isActive() )
return false;
594 delete[] inputBuffer;
595 delete[] outputBuffer;
596 delete[] inDoublesBuffer;
597 delete[] outDoublesBuffer;
604 if( enableProgress ) progressPtr->setTotalSteps( linesNumber );
606 unsigned int col = 0;
607 double inputValue = 0;
608 double outputValue = 0;
610 for(
unsigned int line = 0 ; line < linesNumber ; ++line )
612 for( col = 0 ; col < columnsNumber ; ++col )
614 inRasterBand.
getValue( col, line, inputValue );
615 (this->*remapFuncPtr)( inputValue, outputValue );
616 outRasterBand.
setValue( col, line, std::max( outRangeMin, std::min(
617 outRangeMax, outputValue ) ) );
622 progressPtr->pulse();
623 if( ! progressPtr->isActive() )
return false;
Calculate the standard deviation value.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
int m_blkh
Block height (pixels).
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
te::rst::Raster * m_outRasterPtr
A pointer to a valid initiated raster instance where the result must be written, leave NULL to create...
int getType() const
It returns the data type of the elements in the band.
void(Contrast::* RemapFuncPtrT)(const double &inValue, double &outValue)
Type definition for a remapping function pointer.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
AbstractParameters * clone() const
Create a clone copy of this instance.
Raster Processing functions.
const OutputParameters & operator=(const OutputParameters ¶ms)
double m_offSetGainRemap_gain
Grid * getGrid()
It returns the raster grid.
Contrast output parameters.
static Raster * make()
It creates and returns an empty raster with default raster driver.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
Contrast::InputParameters m_inputParameters
Contrast input execution parameters.
int m_nblocksy
The number of blocks in y.
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
void Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
A rectified grid is the spatial support for raster data.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
te::rst::Raster const * m_inRasterPtr
Input raster.
#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...
bool m_isInitialized
Tells if this instance is initialized.
Abstract parameters base interface.
A raster band description.
A rectified grid is the spatial support for raster data.
int m_blkw
Block width (pixels).
const InputParameters & operator=(const InputParameters ¶ms)
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
virtual Raster * getRaster() const =0
Returns the associated raster.
ContrastType m_type
The contrast type to be applied.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Contrast input parameters.
void offSetGainRemap(const double &inValue, double &outValue)
Remap on gray level using an offset (Contrast::m_offSetGainRemap_offset) and a gain value (Contrast::...
std::auto_ptr< te::rst::Raster > m_createdOutRasterPtr
A pointer to the created output raster instance, or an empty pointer empty if the result must be writ...
bool execLinearContrast()
Execute a linear contrast following the internal parameters.
std::vector< double > m_hECMaxInput
The contrast maximum input greyscale value of each band.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
const Algorithm & operator=(const Algorithm &)
This class implements an iterator to "navigate" over a single band (const).
Calculate the histogram for the real part.
A raster band description.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
bool execHistogramEqualizationContrast()
Execute the histogram equalization contrast following the internal parameters.
void 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)...
static ConstBandIterator begin(const Band *b)
Returns an iterator referring to the first value of the band.
Raster Processing algorithm output parameters base interface.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
int m_nblocksx
The number of blocks in x.
BandProperty * getProperty()
Returns the band property.
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.
std::vector< double > m_sMASCMeanInput
The mean greyscale to be applied in each band.
#define TERP_LOG_AND_THROW(message)
Logs a error message and throws.
std::vector< double > m_sMASCStdInput
The standard deviation to be applied in each band.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
void ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
SummaryTypes
Types for the BandSummary.
bool execSetMeanAndStdContrast()
Execute the histogram equalization contrast following the internal parameters.
static ConstBandIterator end(const Band *b)
Returns an iterator referring to after the end of the iterator.
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Calculate the mean value.
Contrast::OutputParameters * m_outputParametersPtr
Contrast input execution parameters.
double m_offSetGainRemap_offset
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
bool remapBandLevels(const te::rst::Band &inRasterBand, te::rst::Band &outRasterBand, RemapFuncPtrT remapFuncPtr, const bool enableProgress)
Band gray levels remap using a remap function.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Raster Processing algorithm input parameters base interface.
AbstractParameters * clone() const
Create a clone copy of this instance.