30 static ossimTrace traceDebug(
"ossimHistogramRemapper:debug");
32 static const char* STRETCH_MODE[] = {
"linear_one_piece",
33 "linear_1std_from_mean",
34 "linear_2std_from_mean",
35 "linear_3std_from_mean",
36 "linear_auto_min_max",
37 "linear_auto_percentile",
40 static const char NORMALIZED_LOW_CLIP_POINT_KW[] =
"normalized_low_clip_point";
41 static const char NORMALIZED_HIGH_CLIP_POINT_KW[]=
"normalized_high_clip_point";
42 static const char MID_POINT_KW[] =
"mid_point";
43 static const char MIN_OUTPUT_VALUE_KW[] =
"min_output_value";
44 static const char MAX_OUTPUT_VALUE_KW[] =
"max_output_value";
45 static const char STRETCH_MODE_KW[] =
"stretch_mode";
46 static const char HISTOGRAM_FILENAME_KW[] =
"histogram_filename";
48 #ifdef OSSIM_ID_ENABLED 49 static const char OSSIM_ID[] =
"$Id: ossimHistogramRemapper.cpp 23182 2015-03-09 14:30:52Z okramer $";
58 theNormalizedLowClipPoint(),
59 theNormalizedHighClipPoint(),
65 theResetBandIndicesFlag(false)
71 <<
"ossimHistogramRemapper::ossimHistogramRemapper entered...\n";
72 #ifdef OSSIM_ID_ENABLED 74 <<
"OSSIM_ID: " << OSSIM_ID <<
"\n";
88 <<
"ossimHistogramRemapper::initialize entered..." << endl;
100 vector<ossim_uint32> bandList;
107 for(idx = 0; idx < bandList.size();++idx)
150 <<
"ossimHistogramRemapper::initialize exited..." << endl;
237 if(!inputTile.
valid())
287 <<
"\nOutput scalar type is OSSIM_SCALAR_UNKNOWN!\n";
307 <<
"ossimHistogramRemapper::buildTable ERROR!" 308 <<
" Line: " << __LINE__ << endl;
322 T* bandPtr =
static_cast<T*
>(inputTile->
getBuf(band));
324 if (h.
get()&&bandPtr&&outputPtr)
329 <<
"ossimHistogramRemapper::buildLinearTable DEBUG:" 330 <<
"\nband: " << band
341 <<
"ossimHistogramRemapper::buildTable ERROR!" 342 <<
" Line: " << __LINE__ << endl;
363 min_clip_value = floor(min_clip_value);
364 max_clip_value = ceil(max_clip_value);
371 gain = (MAX_PIX-MIN_PIX+1)/(max_clip_value-min_clip_value);
375 gain = (MAX_PIX-MIN_PIX)/(max_clip_value-min_clip_value);
380 for(idx = 0; idx < PPB;++idx)
382 if ( bandPtr[idx] != NULL_PIX )
385 if (p < min_clip_value)
389 else if (p > max_clip_value)
395 p = ((p - min_clip_value) * gain) + MIN_PIX;
399 static_cast<T
>( p >= MIN_PIX ? ( p <= MAX_PIX ? p : MAX_PIX ) : MIN_PIX );
403 outputPtr[idx] = NULL_PIX;
440 if (zero_based_band >= BANDS)
443 <<
"ossimHistogramRemapper::setLowNormalizedClipPoint ERROR:" 444 <<
"\nband " << zero_based_band <<
" is out of range!" 445 <<
"\nhighest band: " << (BANDS-1) << endl;
476 if (zero_based_band >= BANDS)
479 <<
"ossimHistogramRemapper::setHighNormalizedClipPoint ERROR:" 480 <<
"\nband " << zero_based_band <<
" is out of range!" 481 <<
"\nhighest band: " << (BANDS-1) << endl;
568 if (zero_based_band >= BANDS)
571 <<
"ossimHistogramRemapper::setMidPoint ERROR:" 572 <<
"\nband " << zero_based_band <<
" is out of range!" 573 <<
"\nhighest band: " << (BANDS-1) << endl;
604 if (zero_based_band >= BANDS)
607 <<
"ossimHistogramRemapper::setMinOutputValue ERROR:" 608 <<
"\nband " << zero_based_band <<
" is out of range!" 609 <<
"\nhighest band: " << (BANDS-1) << endl;
643 if (zero_based_band >= BANDS)
646 <<
"ossimHistogramRemapper::setMidPoint ERROR:" 647 <<
"\nband " << zero_based_band <<
" is out of range!" 648 <<
"\nhighest band: " << (BANDS-1) << endl;
677 <<
"ossimHistogramRemapper::getLowNormalizedClipPoint ERROR:" 678 <<
"\nband " << zero_based_band <<
" is out of range!" 715 <<
"ossimHistogramRemapper::getHighNormalizedClipPoint ERROR:" 716 <<
"\nband " << zero_based_band <<
" is out of range!" 836 <<
"ossimHistogramRemapper::getMidPoint ERROR:" 837 <<
"\nband " << zero_based_band <<
" is out of range!" 874 <<
"ossimHistogramRemapper::getMinOutputValue ERROR:" 875 <<
"\nband " << zero_based_band <<
" is out of range!" 912 <<
"ossimHistogramRemapper::getMaxOutputValue ERROR:" 913 <<
"\nband " << zero_based_band <<
" is out of range!" 942 static const char MODULE[] =
"ossimHistogramRemapper::loadState";
945 CLOG <<
" Entered..." 946 <<
"\nprefix: " << prefix << endl;
952 const char* lookup = 0;
955 lookup = kwl.
find(prefix, HISTOGRAM_FILENAME_KW);
961 <<
"ossimHistogramRemapper::loadState ERROR!" 962 <<
"\nCould not open file: " << lookup
963 <<
"\nReturning..." << endl;
985 keyword = NORMALIZED_LOW_CLIP_POINT_KW;
986 bands = kwl.
numberOf(prefix, keyword);
996 <<
"ossimHistogramRemapper::loadState DEBUG:" 997 <<
"\nBands: " << bands
1007 keyword = NORMALIZED_LOW_CLIP_POINT_KW;
1011 lookup = kwl.
find(prefix, keyword);
1018 keyword = NORMALIZED_HIGH_CLIP_POINT_KW;
1022 lookup = kwl.
find(prefix, keyword);
1029 keyword = MID_POINT_KW;
1033 lookup = kwl.
find(prefix, keyword);
1040 keyword = MIN_OUTPUT_VALUE_KW;
1044 lookup = kwl.
find(prefix, keyword);
1051 keyword = MAX_OUTPUT_VALUE_KW;
1055 lookup = kwl.
find(prefix, keyword);
1063 lookup = kwl.
find(prefix, STRETCH_MODE_KW);
1105 CLOG <<
"ossimHistogramRemapper::loadState DEBUG:" 1107 <<
"\nExited..." << endl;
1113 const char* prefix)
const 1118 HISTOGRAM_FILENAME_KW,
1139 keyword = NORMALIZED_LOW_CLIP_POINT_KW;
1149 keyword = NORMALIZED_HIGH_CLIP_POINT_KW;
1159 keyword = MID_POINT_KW;
1170 keyword = MIN_OUTPUT_VALUE_KW;
1180 keyword = MAX_OUTPUT_VALUE_KW;
1221 if( mode ==
"linear_one_piece")
1225 else if(mode ==
"linear_1std_from_mean")
1229 else if(mode ==
"linear_2std_from_mean")
1233 else if(mode ==
"linear_3std_from_mean")
1237 else if(mode ==
"linear_auto_min_max")
1241 else if(mode ==
"linear_auto_percentile")
1281 <<
"ossimHistogramRemapper::buildTable ERROR!" 1282 <<
"\nUnknown stretch type!" << endl;
1290 <<
"ossimHistogramRemapper::buildTable DEBUG:\n" << endl;
1354 <<
"ossimHistogramRemapper::buildLinearTable OSSIM_SCALAR_UNKNOWN!" << endl;
1410 <<
"ossimTableRemapper::buildTable OSSIM_SCALAR_UNKNOWN!" 1467 <<
"ossimHistogramRemapper::buildAutoLinearPercentileTableTemplate OSSIM_SCALAR_UNKNOWN!" 1495 <<
"ossimHistogramRemapper::buildTable ERROR!" 1496 <<
" Line: " << __LINE__ << endl;
1501 T* table =
reinterpret_cast<T*
>(&
theTable.front());
1513 <<
"ossimHistogramRemapper::buildLinearTable DEBUG:" 1514 <<
"\nband: " << band
1525 <<
"ossimHistogramRemapper::buildTable ERROR!" 1526 <<
" Line: " << __LINE__ << endl;
1541 min_clip_value = floor(min_clip_value);
1542 max_clip_value = ceil(max_clip_value);
1543 gain = (MAX_PIX-MIN_PIX)/(max_clip_value-min_clip_value);
1549 gain = ((MAX_PIX-MIN_PIX)+1)/(max_clip_value-min_clip_value);
1552 table[index] = NULL_PIX;
1562 if (p <= min_clip_value)
1566 else if (p >= max_clip_value)
1572 p = ((p - min_clip_value) * gain) + MIN_PIX - 1.0;
1579 table[index] =
static_cast<T
>(p+0.5);
1600 <<
"ossimHistogramRemapper::buildAutoLinearMinMaxTableTemplate ERROR!" 1601 <<
" Line: " << __LINE__ << endl;
1621 double newCount = 0.0;
1622 double nextPercentage = 0.0;
1623 double percentage = 0.0;
1629 bool hasValue = (counts[idx] > 0)&&(counts[idx+1]);
1632 newCount += counts[idx];
1634 percentage = newCount / count;
1635 nextPercentage = (newCount + counts[idx+1]) / count;
1638 if (hasValue &&((std::fabs(percentage - bias) <
1639 std::fabs(nextPercentage - bias))))
1647 for (idx =
n-1; idx > 0; idx--)
1649 bool hasValue = (counts[idx] > 0)&&(counts[idx-1]);
1650 newCount += counts[idx];
1651 percentage = newCount / count;
1652 nextPercentage = (newCount + counts[idx-1]) / count;
1653 if (hasValue && ((std::fabs(percentage - bias) <
1654 std::fabs(nextPercentage - bias))))
1693 <<
"ossimHistogramRemapper::buildTable ERROR!" 1694 <<
" Line: " << __LINE__ << endl;
1740 <<
"ossimHistogramRemapper::buildLinearStdFromMean DEBUG:" 1741 <<
"\nband: " << band
1742 <<
"\nmean: " << mean
1743 <<
"\nstddev: " << stdDev
1744 <<
"\nlow clip: " << lowClip
1745 <<
"\nhigh clip: " << highClip
1763 <<
"ossimHistogramRemapper::buildAutoLinearMinMaxTableTemplate ERROR!" 1764 <<
" Line: " << __LINE__ << endl;
1783 if(low < 0) low = 0;
1784 if(high < 0) high =
n-1;
1919 os << setiosflags(ios::fixed) << setprecision(15)
1920 <<
"\nossimHistogramRemapper::print:" 1926 <<
"\ntheTableSizeInBytes: " <<
theTable.size()
1932 os <<
"\ntheNormalizedLowClipPoint[" << band <<
"]: " 1934 <<
"\ntheNormalizedHighClipPoint[" << band <<
"]: " 1936 <<
"\ntheMidPoint[" << band <<
"]: " 1938 <<
"\ntheMinOutputValue[" << band <<
"]: " 1940 <<
"\ntheMaxOutputValue[" << band <<
"]: " 1947 os <<
"theBandList[" << i <<
"]: " <<
theBandList[i] << endl;
1967 values_per_band = 256;
1968 bytes_per_pixel = 1;
1973 values_per_band = 2048;
1974 bytes_per_pixel = 2;
1978 values_per_band = 4096;
1979 bytes_per_pixel = 2;
1983 values_per_band = 8192;
1984 bytes_per_pixel = 2;
1988 values_per_band = 16384;
1989 bytes_per_pixel = 2;
1993 values_per_band = 32768;
1994 bytes_per_pixel = 2;
2000 values_per_band = 65536;
2001 bytes_per_pixel = 2;
2007 values_per_band = 65536;
2008 bytes_per_pixel = 4;
2014 bytes_per_pixel = 4;
2019 bytes_per_pixel = 4;
2020 values_per_band = 65536;
2026 bytes_per_pixel = 8;
2027 values_per_band = 65536;
2032 bytes_per_pixel = 8;
2033 values_per_band = 65536;
2059 values_per_band = h->
GetRes();
2068 ossim_uint32 size_in_bytes = values_per_band * BANDS * bytes_per_pixel;
2160 <<
"ossimHistogramRemapper::verifyEnabled theBypassFlag: " 2192 if (histogram_band < theHistogram->getNumberOfBands())
2215 vector<ossim_uint32> bandList;
2225 return bandList[input_band];
2230 return ossimString(
"Histogram Remapper, filter with controls for histogram stretching.");
2302 bool result =
false;
2303 if(inputIndex == 0) result =
dynamic_cast<const ossimImageSource*
>(object)!=0;
16 bit unsigned integer (15 bits used)
virtual void setNumberOfInputs(ossim_int32 numberOfInputs)
Will set the number of inputs.
virtual void getOutputBandList(std::vector< ossim_uint32 > &bandList) const
StretchMode theStretchMode
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
RemapTableType theTableType
virtual bool importHistogram(const ossimFilename &inputFile)
virtual ossim_uint32 getNumberOfInputBands() const
void setHighClipPoint(const ossim_float64 &clip)
Sets the high clip point.
ossimRefPtr< ossimHistogram > getHistogram(ossim_uint32 band, ossim_uint32 resLevel=0)
ossim_uint32 numberOf(const char *str) const
virtual ossim_uint32 getNumberOfBands() const
vector< ossim_float64 > theNormalizedLowClipPoint
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void buildAutoLinearMinMaxTableTemplate(T dummy)
virtual void setImageRectangle(const ossimIrect &rect)
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
void buildAutoLinearMinMaxTable()
ossim_float64 getLowNormalizedClipPoint() const
Returns the normalized low clip point which is the average of all bands.
void buildLinearTableStdFromMean()
Sets clip points using mean and standard deviations then calls buildLinearTable method.
ossim_float64 getHighClipPoint() const
Returns the high clip point which is the average of all bands.
virtual void populateHistogram(ossimRefPtr< ossimMultiBandHistogram > histo)
Represents serializable keyword/value map.
virtual ostream & print(ostream &os) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
void buildAutoLinearPercentileTable()
const char * find(const char *key) const
float getHighFractionFromValue(float val) const
void setHighNormalizedClipPoint(const ossim_float64 &clip)
Sets the high clip point.
ossimRefPtr< ossimMultiResLevelHistogram > theHistogram
ossimFilename getHistogramFile() const
Returns the currently opened histogram.
double nan()
Method to return ieee floating point double precision NAN.
ossimRefPtr< ossimImageData > theTile
bool computeHistogram(const ossimIrect &roi)
Compute the histogram from input connection and region of interest.
vector< ossim_uint32 > theBandList
ossimHistogramRemapper & operator=(const ossimHistogramRemapper &hr)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ~ossimHistogramRemapper()
virtual destructor
std::vector< ossim_uint8 > theTable
vector< ossim_float64 > theNormalizedHighClipPoint
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_float64 getMaxOutputValue() const
Returns the maximum output value which is the average of all bands.
void setLowClipPoint(const ossim_float64 &clip)
Sets the low clip point.
ossimRefPtr< ossimMultiResLevelHistogram > getHistogram()
ossim_uint32 getHistogramBand(ossim_uint32 input_band) const
Returns the histogram band that maps to the input band.
virtual ossimDataObjectStatus getDataObjectStatus() const
void setupTable()
Initialized base class (ossimTableRemapper) values:
16 bit unsigned integer (14 bits used)
ossim_uint32 toUInt32() const
16 bit unsigned integer (13 bits used)
void initializeClips()
Uses getNumberOfInputBands() to determine BANDS then calls initializeClips(BANDS) ...
float GetMaxValFromIndex(ossim_uint32 idx) const
unsigned short ossim_uint16
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 resLevel=0)
ossim_float64 getLowClipPoint() const
Returns the low clip point which is the average of all bands.
bool theResetBandIndicesFlag
void setMidPoint(const ossim_float64 &value)
Sets the mid clip point.
virtual void initialize()
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
ossim_uint32 getNumberOfStretchModes() const
Returns the number of stretch modes.
void setStretchMode(StretchMode mode, bool rebuildTableFlag=false)
Sets remap mode to mode.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void makeClean()
If we are dirty then it will init what it needs and then set the dirty back to false;.
void initializeMinMaxOutput()
vector< ossim_float64 > theMinOutputValue
void verifyEnabled()
This set theBypassFlag.
float GetValFromIndex(ossim_uint32 idx) const
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
ossim_float64 getMinOutputValue() const
Returns the minimum output value which is the average of all bands.
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
float GetStandardDev() const
virtual ossimString getLongName() const
StretchMode getStretchMode() const
Returns the current enumerated node.
os2<< "> n<< " > nendobj n
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to the save the state to a keyword list.
virtual int GetIndex(float) const
void allocate(const ossimIrect &rect)
virtual void addHistogram(ossimMultiBandHistogram *histo)
static const char * NUMBER_BANDS_KW
static ossimString downcase(const ossimString &aString)
float HighClipVal(float clip_fraction) const
static const char * BAND_KW
vector< ossim_float64 > theMaxOutputValue
virtual void initialize()
ossim_uint32 getNumberOfBands(ossim_uint32 resLevel=0) const
void setMinOutputValue(const ossim_float64 &value)
Sets the min output value.
float LowClipVal(float clip_fraction) const
ossim_float64 getMidPoint() const
Returns the mid clip point which is the average of all bands.
float GetMinValFromIndex(ossim_uint32 idx) const
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
void applyLinearStretch(T dummy, ossimRefPtr< ossimImageData > &inputTile)
ossim_uint32 theTableBandCount
ossimHistogramRemapper()
default constructor
void buildAutoLinearPercentileTableTemplate(T dummy)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
vector< ossim_float64 > theMidPoint
ossimScalarType theOutputScalarType
virtual const void * getBuf() const
ossimString getStretchModeString() const
Returns the string for current remap mode.
ossim_uint32 theTableBinCount
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossim_float64 getHighNormalizedClipPoint() const
Returns the normalized High clip point which is the average of all bands.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
void setBypassFlag(bool flag)
Sets theBypassFlag.
virtual ossimString getShortName() const
void setStretchModeAsString(const ossimString &mode, bool rebuildTableFlag=false)
Stretch mode values can be linear_one_piece, linear_1std_from_mean, linear_2std_from_mean, linear_3std_from_mean, linear_auto_min_max, If rebuildTableFlag is true, the table will be built at this time; else just the dirty flag is set.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
float ComputeArea(float low, float high) const
#define RTTI_DEF1(cls, name, b1)
ossimDataObjectStatus
Definitions for data object status.
bool canConnectMyInputTo(ossim_int32 inputIndex, const ossimConnectableObject *object) const
Will test for the input being a ossimHistogramSource and allow pulling the histogram from a histogram...
void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histogram)
Sets the histogram.
void create(const ossimImageSource *input)
void setLowNormalizedClipPoint(const ossim_float64 &clip)
Sets the low clip point.
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossimFilename getHistogramFile() const
float getLowFractionFromValue(float val) const
float SetCount(float pixelval, float count)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool openHistogram(const ossimFilename &histogram_file)
Open the histogram file.
std::basic_ostream< char > ostream
Base class for char output streams.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
void setMaxOutputValue(const ossim_float64 &value)
Sets the max output value.
16 bit unsigned integer (12 bits used)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.