OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ossimHistogram Class Reference

#include <ossimHistogram.h>

Inheritance diagram for ossimHistogram:
ossimObject ossimReferenced

Classes

class  ossimProprietaryHeaderInformation
 

Public Types

enum  FillAlgorithmType { HISTOGRAM_FILL_DEFAULT = 0, HISTOGRAM_FILL_THIN_PLATE = 1 }
 

Public Member Functions

 ossimHistogram ()
 
 ossimHistogram (int xres, float min, float max)
 
 ossimHistogram (float *, float *, int)
 
 ossimHistogram (const ossimHistogram &his)
 
 ossimHistogram (const ossimHistogram *, float width)
 
 ossimHistogram (const double *samples, ossim_uint32 size, ossim_uint32 numBins)
 Uses samples array to establish a histogram with numBins: More...
 
virtual int GetIndex (float) const
 
ossimHistogramfillInteriorEmptyBins (int type=HISTOGRAM_FILL_THIN_PLATE) const
 
ossimHistogramScale (float scale_factor)
 
ossimHistogramCumulativeGreaterThanEqual () const
 
ossimHistogramCumulativeLessThanEqual () const
 
ossimHistogramNonMaximumSupress (int radius=1, bool cyclic=false)
 
void create (int xres, float val1, float val2)
 
void UpCount (float newval, float occurences=1)
 
float GetCount (float uval) const
 
float SetCount (float pixelval, float count)
 
float GetMinVal () const
 
float GetMaxVal () const
 
float GetMaxCount () const
 
float GetRangeMin () const
 
float GetRangeMax () const
 
float * GetVals ()
 
const float * GetVals () const
 
float * GetCounts ()
 
const float * GetCounts () const
 
int GetRes () const
 
float GetBucketSize () const
 
float * GetMinValAddr ()
 
float * GetMinCountAddr ()
 
const float * GetMinValAddr () const
 
const float * GetMinCountAddr () const
 
float ComputeArea (float low, float high) const
 
float ComputeArea () const
 
float getLowFractionFromValue (float val) const
 
float getHighFractionFromValue (float val) const
 
float LowClipVal (float clip_fraction) const
 
float HighClipVal (float clip_fraction) const
 
float GetValFromIndex (ossim_uint32 idx) const
 
float GetMinValFromIndex (ossim_uint32 idx) const
 
float GetMaxValFromIndex (ossim_uint32 idx) const
 
int GetValIndex (float val) const
 
float GetMean () const
 
float GetStandardDev () const
 
void Print () const
 
void Dump (char *) const
 
int WritePlot (const char *fname) const
 
virtual ~ossimHistogram ()
 
virtual bool importHistogram (const ossimFilename &inputFile)
 
virtual bool importHistogram (istream &in)
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
virtual bool saveState (ossimRefPtr< ossimXmlNode > xmlNode) const
 
virtual bool loadState (const ossimRefPtr< ossimXmlNode > xmlNode)
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Protected Member Functions

virtual void deleteAll ()
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

float * m_vals
 
float * m_counts
 
int m_num
 
float m_delta
 
float m_vmin
 
float m_vmax
 
float m_mean
 
float m_standardDev
 

Private Attributes

int m_statsConsistent
 

Detailed Description

Definition at line 28 of file ossimHistogram.h.

Member Enumeration Documentation

◆ FillAlgorithmType

Enumerator
HISTOGRAM_FILL_DEFAULT 
HISTOGRAM_FILL_THIN_PLATE 

Definition at line 79 of file ossimHistogram.h.

Constructor & Destructor Documentation

◆ ossimHistogram() [1/6]

ossimHistogram::ossimHistogram ( )

Definition at line 46 of file ossimHistogram.cpp.

Referenced by CumulativeGreaterThanEqual(), CumulativeLessThanEqual(), fillInteriorEmptyBins(), NonMaximumSupress(), and Scale().

47  :
48  m_statsConsistent(MEAN_FLAG | SD_FLAG),
49  m_vals(new float [1]),
50  m_counts(new float [1]),
51  m_num(0),
52  m_delta(0.0),
53  m_vmin(0),
54  m_vmax(0),
55  m_mean(0.0),
56  m_standardDev(0.0)
57 {
58  m_vals[0] = 0.0;
59  m_counts[0] = 0.0;
60 }

◆ ossimHistogram() [2/6]

ossimHistogram::ossimHistogram ( int  xres,
float  min,
float  max 
)

Definition at line 62 of file ossimHistogram.cpp.

63  :
64  m_statsConsistent(MEAN_FLAG | SD_FLAG),
65  m_vals(new float [xres]),
66  m_counts(new float [xres]),
67  m_num(xres),
68  m_delta(0.0),
69  m_vmin(0),
70  m_vmax(0),
71  m_mean(0.0),
72  m_standardDev(0.0)
73 {
74  m_vmax = MAX(val1, val2);
75  m_vmin = MIN(val1, val2);
76 
77  //---
78  // Set the delta which is used to index the bins.
79  // Note: that using "(m_vmax - m_vmin) / xres" was dropping the
80  // last bin on integer data.
81  //---
82  if ( (m_vmax - m_vmin + 1) == xres )
83  {
84  m_delta = 1.0;
85  }
86  else
87  {
88  m_delta = (m_vmax - m_vmin) / xres;
89  }
90 
91  m_mean = (float)((m_vmax + m_vmin)/2.0);
92  m_standardDev = (float)((m_vmax - m_vmin)/(2.0*sqrt(3.0)));
93  int i = 0;
94 
95  if (m_vals == NULL || m_counts == NULL)
96  {
97  fprintf(stderr, "Histogram : Ran out of memory for arrays.\n");
98  m_vals = NULL;
99  m_counts = NULL;
100  m_num = 0;
101  m_vmin = 0;
102  m_vmax = 0;
103  m_delta = 0.0;
104  }
105  else
106  {
107  //std::cout << std::setprecision(15) << m_vmin << ", " << m_vmax << ", " <<m_delta <<", "<< xres << std::endl;
108  for(i = 0; i < xres; i++)
109  {
110  m_vals[i] = m_vmin + m_delta * (float)(i + 0.5);
111  //std::cout << m_vals[i] << std::endl;
112  m_counts[i] = 0.0;
113  }
114  }
115 }
#define MAX(x, y)
#define MIN(x, y)

◆ ossimHistogram() [3/6]

ossimHistogram::ossimHistogram ( float *  uvals,
float *  ucounts,
int  xres 
)

Definition at line 117 of file ossimHistogram.cpp.

118  :
119  m_statsConsistent(MEAN_FLAG | SD_FLAG),
120  m_vals(uvals),
121  m_counts(ucounts),
122  m_num(xres),
123  m_delta(0.0),
124  m_vmin(0),
125  m_vmax(0),
126  m_mean(0.0),
127  m_standardDev(0.0)
128 {
129  if ( ( xres >= 2 ) && uvals && ucounts )
130  {
131  m_delta = m_vals[1] - m_vals[0]; // Changed this from delta = 1.0
132  // m_vmax = GetMaxVal();
133  // m_vmin = GetMinVal(); JAF version
134  m_vmin = uvals[0] - .5f*m_delta;
135  m_vmax = uvals[m_num-1] + .5f*m_delta;
136  m_mean = GetMean();
138  }
139 }
float GetMean() const
float GetStandardDev() const

◆ ossimHistogram() [4/6]

ossimHistogram::ossimHistogram ( const ossimHistogram his)

Definition at line 186 of file ossimHistogram.cpp.

References GetBucketSize(), GetCounts(), GetMaxVal(), GetMean(), GetMinVal(), GetRes(), GetStandardDev(), GetVals(), m_counts, m_delta, m_mean, m_num, m_standardDev, m_statsConsistent, m_vals, m_vmax, and m_vmin.

187 :
189 m_vals(0),
190 m_counts(0),
191 m_num(0),
192 m_delta(0.0),
193 m_vmin(0),
194 m_vmax(0),
195 m_mean(0.0),
196 m_standardDev(0.0)
197 {
198 
199  int i = 0;
200  m_num = his.GetRes();
201 
202  m_vals = new float[m_num];
203  const float* his_vals = his.GetVals();
204 
205  m_counts = new float[m_num];
206  const float* his_counts = his.GetCounts();
207 
208  if (m_vals == NULL || m_counts == NULL)
209  {
210  fprintf(stderr, "Histogram : Ran out of memory for arrays.\n");
211  m_vals = NULL;
212  m_counts = NULL;
213  m_num = 0;
214  m_vmin = 0;
215  m_vmax = 0;
216  m_delta = 0.0;
217  m_statsConsistent = 0;
218  return;
219  }
220 
221  m_mean = his.GetMean();
223 
224  for(i=0; i<m_num; i++)
225  {
226  m_vals[i] = his_vals[i];
227  m_counts[i] = his_counts[i];
228  }
229  m_vmax = his.GetMaxVal();
230  m_vmin = his.GetMinVal();
231  m_delta = his.GetBucketSize();
232 
233  m_statsConsistent = 0;
234  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
235 }
float GetBucketSize() const
int GetRes() const
float GetMean() const
float GetStandardDev() const
float GetMinVal() const
float * GetCounts()
float * GetVals()
float GetMaxVal() const

◆ ossimHistogram() [5/6]

ossimHistogram::ossimHistogram ( const ossimHistogram his,
float  width 
)

Definition at line 241 of file ossimHistogram.cpp.

References GetBucketSize(), GetRes(), GetVals(), m_counts, m_delta, m_mean, m_num, m_standardDev, m_statsConsistent, m_vals, m_vmax, and m_vmin.

242 :
244 m_vals(0),
245 m_counts(0),
246 m_num(0),
247 m_delta(0.0),
248 m_vmin(0),
249 m_vmax(0),
250 m_mean(0.0),
251 m_standardDev(0.0)
252 {
253 
255 
256 // Attributes of original histogram
257 
258  float del = his->GetBucketSize();
259  int max_index = his->GetRes() - 1;
260  float minvalue = his->GetVals()[0] - del*.5f;
261  float maxvalue = his->GetVals()[max_index] + del*.5f;
262 
263 
264 // Intialize a new histogram
265  if(width == del) m_num = his->GetRes();
266  else if(!(width == 0.0))
267  m_num = (int)ceil((maxvalue - minvalue)/width);
268  else
269  m_num = 1; // This shouldn't happen anyway.
270 
271  m_vals = new float [m_num];
272  m_counts = new float [m_num];
273  m_delta = width;
274  float mean_val = (maxvalue + minvalue)/2.0f;
275  float half_range = (m_num * m_delta)/2.0f;
276  m_vmax = mean_val + half_range;
277  m_vmin = mean_val - half_range;
278  int i = 0;
279 
280  if (m_vals == NULL || m_counts == NULL)
281  {
282  fprintf(stderr,
283  "Histogram : Ran out of memory for arrays.\n");
284  m_vals = NULL;
285  m_counts = NULL;
286  m_num = 0;
287  m_vmin = 0;
288  m_vmax = 0;
289  m_delta = 0.0;
290  m_mean = 0.0;
291  m_standardDev = 0.0;
292  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
293  return;
294 
295  }
296 
297  else
298  {
299  for(i = 0; i < m_num; i++)
300  {
301  m_vals[i] = m_vmin + m_delta * (i + 0.5f);
302  m_counts[i] = 0.0;
303  }
304  }
305 
306 
307 // Cases:
308 
309 
310  if(width == del) // Then just copy his
311  {
312  const float* his_counts = his->GetCounts();
313  for(i=0; i<m_num; i++)
314  m_counts[i] = his_counts[i];
315  m_mean = GetMean();
317  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
318  return;
319  }
320 
321 
322  if(del > width) // Then interpolate his m_counts.
323  {
324 
325 // Boundary conditions:
326 // Start
327  float his_start = minvalue + .5f*del;
328  float start = m_vmin + .5f*m_delta;
329  float c0 = his->GetCount(his_start);
330  float c1 = his->GetCount(his_start + del);
331  float s0 = (c1 - c0)/del;
332 
333  for(float x = start; x <= (his_start + del + m_delta);)
334  {
335  float interp = s0 * (x - his_start) + c0;
336  if(interp < 0) interp = 0; //Can be negative
337  SetCount(x,interp);
338  x += width;
339  }
340 // End
341  float his_end = maxvalue - .5f*del;
342  float end = m_vmax - .5f*m_delta;
343  float cn = his->GetCount(his_end);
344  float cn_1 = his->GetCount(his_end - del);
345  float sn = (cn_1 - cn)/del;
346 
347  for(float y = end; y >= (his_end - del + m_delta);)
348  {
349  float interp = sn * (his_end - y) + cn;
350  if(interp < 0) interp = 0; //Can be negative
351  SetCount(y, interp);
352  y -= m_delta;
353  }
354 // Interior Loop
355 
356  for(float z = his_start + del; z <= (his_end - del);)
357  {
358  float ci = his->GetCount(z);
359  float ci_1 = his->GetCount(z-del);
360  float cip1 = his->GetCount(z+del);
361  float deriv = (cip1 - ci_1)/(2.0f*del);
362  float second_drv =
363  ((cip1 + ci_1)/2.0f - ci)/(del*del);
364  int fine_x_index = GetIndex(z);
365  if (fine_x_index < 0)
366  {
367  if (z<m_vmin) fine_x_index = 0;
368  else fine_x_index = m_num-1;
369  }
370  float fine_x = m_vals[fine_x_index];
371  for(float xfine = fine_x; xfine < z + del;)
372  {
373  float interp = ci + deriv*(xfine -z) +
374  second_drv*(xfine - z)*(xfine - z);
375 
376  if(interp < 0) interp = 0; //Can be negative
377  SetCount(xfine, interp);
378  xfine += width;
379  }
380  z += del;
381  }
382  }
383 
384 
385  if(del < width) //Just accumulate samples from his into larger bins
386  {
387  if( del != 0.0){
388  float his_start = minvalue + .5f*del;
389  float his_end = maxvalue - .5f*del;
390  for(float x = his_start; x <= his_end;)
391  {
392  SetCount(x, (GetCount(x) + his->GetCount(x)));
393  x += del;
394  }
395  }
396  }
397  m_mean = GetMean();
400  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
401 }
ossim_uint32 x
float GetCount(float uval) const
float GetBucketSize() const
ossim_uint32 y
int GetRes() const
float GetMean() const
float GetStandardDev() const
virtual int GetIndex(float) const
float * GetCounts()
float * GetVals()
float SetCount(float pixelval, float count)

◆ ossimHistogram() [6/6]

ossimHistogram::ossimHistogram ( const double *  samples,
ossim_uint32  size,
ossim_uint32  numBins 
)

Uses samples array to establish a histogram with numBins:

Definition at line 140 of file ossimHistogram.cpp.

References GetMean(), GetStandardDev(), m_counts, m_delta, m_num, m_vals, m_vmax, m_vmin, size, and UpCount().

141  :
143  m_vals(0),
144  m_counts(0),
145  m_num((int)xres),
146  m_delta(0.0),
147  m_vmin(0),
148  m_vmax(0),
149  m_mean(0.0),
150  m_standardDev(0.0)
151 {
152  if ((size == 0) || (xres == 0))
153  return;
154 
155  // scan the dataset for min/max:
156  m_vmin=(float)(data[0]);
157  m_vmax=(float)(data[0]);
158  for (ossim_uint32 i=1; i<size; ++i)
159  {
160  if ((float)(data[i]) < m_vmin)
161  m_vmin = (float)(data[i]);
162  else if ((float)(data[i]) > m_vmax)
163  m_vmax = (float)(data[i]);
164  }
165 
166  // Allocate histogram:
167  m_delta = (m_vmax - m_vmin) / m_num;
168  m_vals = new float [m_num];
169  m_counts = new float [m_num];
170  for (ossim_int32 i=0; i<m_num; ++i)
171  {
172  m_vals[i] = m_vmin + m_delta * (i + 0.5);
173  m_counts[i] = 0.0;
174  }
175 
176  // compute histogram:
177  for (ossim_uint32 i=0; i<size; i++)
178  UpCount((float)(data[i]));
179 
180  GetMean();
181  GetStandardDev();
182 }
float GetMean() const
yy_size_t size
float GetStandardDev() const
unsigned int ossim_uint32
void UpCount(float newval, float occurences=1)
int ossim_int32

◆ ~ossimHistogram()

ossimHistogram::~ossimHistogram ( )
virtual

Definition at line 1300 of file ossimHistogram.cpp.

References deleteAll().

1301 {
1302  deleteAll();
1303 }
virtual void deleteAll()

Member Function Documentation

◆ ComputeArea() [1/2]

float ossimHistogram::ComputeArea ( float  low,
float  high 
) const

Definition at line 1051 of file ossimHistogram.cpp.

References GetIndex(), GetMaxVal(), GetMinVal(), m_counts, m_num, and m_vmin.

1052 {
1053  float sum = 0.0;
1054  float maxval = GetMaxVal();
1055  float minval = GetMinVal();
1056 
1057  if (low < minval) low = minval;
1058  if (high > maxval) high = maxval;
1059 
1060  if (low <= high)
1061  {
1062  int indexlow, indexhigh;
1063  indexlow = (int) GetIndex(low);
1064  if (indexlow < 0)
1065  {
1066  if (low<m_vmin) indexlow = 0;
1067  else indexlow = m_num-1;
1068  }
1069  indexhigh = (int) GetIndex(high);
1070  if (indexhigh < 0)
1071  {
1072  if (high<m_vmin) indexhigh = 0;
1073  else indexhigh = m_num-1;
1074  }
1075  int i=indexlow;
1076 
1077  while (i<=indexhigh)
1078  {
1079  sum+= m_counts[i];
1080  i++;
1081  }
1082  }
1083 
1084  return sum;
1085 }
virtual int GetIndex(float) const
float GetMinVal() const
float GetMaxVal() const

◆ ComputeArea() [2/2]

float ossimHistogram::ComputeArea ( ) const

Definition at line 1089 of file ossimHistogram.cpp.

References GetMaxVal(), GetMinVal(), m_vmax, and m_vmin.

Referenced by HighClipVal(), LowClipVal(), and Print().

1090 {
1091  float m_vmin = this->GetMinVal();
1092  float m_vmax = this->GetMaxVal();
1093  if(m_vmin>m_vmax)
1094  {
1095  float temp = m_vmin;
1096  m_vmin = m_vmax;
1097  m_vmax = temp;
1098  }
1099  return this->ComputeArea(m_vmin, m_vmax);
1100 }
float GetMinVal() const
float ComputeArea() const
float GetMaxVal() const

◆ create()

void ossimHistogram::create ( int  xres,
float  val1,
float  val2 
)

Definition at line 403 of file ossimHistogram.cpp.

References deleteAll(), m_counts, m_delta, m_mean, m_num, m_standardDev, m_statsConsistent, m_vals, m_vmax, m_vmin, MAX, and MIN.

Referenced by importHistogram(), and loadState().

404 {
405  // clear all the data
406  deleteAll();
407 
408  // now set it up and initialize;
409  xres = xres >0? xres:1;
410 
411  m_vals = new float [xres];
412  m_counts = new float [xres];
413  m_num = xres;
414  m_vmax = MAX(val1, val2);
415  m_vmin = MIN(val1, val2);
416 
417  m_delta = (m_vmax - m_vmin) / xres;
418  m_mean = (float)((m_vmax + m_vmin)/2.0);
419  m_standardDev = (float)((m_vmax - m_vmin)/(2.0*sqrt(3.0)));
420  m_statsConsistent = 0;
421  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
422  int i = 0;
423  if (m_vals == NULL || m_counts == NULL)
424  {
425  ossimNotify(ossimNotifyLevel_FATAL) << "Histogram : Ran out of memory for arrays.\n";
426  m_vals = NULL;
427  m_counts = NULL;
428  m_num = 0;
429  m_vmin = 0;
430  m_vmax = 0;
431  m_delta = 0.0;
432  }
433  else
434  {
435  for(i = 0; i < xres; i++)
436  {
437  m_vals[i] = m_vmin + m_delta * (float)(i + 0.5);
438  m_counts[i] = 0.0;
439  }
440  }
441 }
virtual void deleteAll()
#define MAX(x, y)
#define MIN(x, y)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ CumulativeGreaterThanEqual()

ossimHistogram * ossimHistogram::CumulativeGreaterThanEqual ( ) const

Definition at line 573 of file ossimHistogram.cpp.

References GetCounts(), GetRes(), and ossimHistogram().

574 {
575  ossimHistogram* cum_his = new ossimHistogram(*this);
576  const float* density_counts = this->GetCounts();
577  int res = this->GetRes();
578 
579  // Intitialize cumulative m_counts
580  float* cum_counts = cum_his->GetCounts();
581  int i = 0;
582  for(i=0; i < res; i++)
583  cum_counts[i] = 0;
584 
585  cum_counts[res-1] = density_counts[res-1];
586  for(i = res-2; i>=0; --i)
587  {
588  cum_counts[i] += (density_counts[i] + cum_counts[i+1]);
589  }
590 
591  return cum_his;
592 }
int GetRes() const
float * GetCounts()

◆ CumulativeLessThanEqual()

ossimHistogram * ossimHistogram::CumulativeLessThanEqual ( ) const

Definition at line 594 of file ossimHistogram.cpp.

References GetCounts(), GetRes(), and ossimHistogram().

595 {
596  ossimHistogram* cum_his = new ossimHistogram(*this);
597  const float* density_counts = this->GetCounts();
598  int res = this->GetRes();
599 
600  // Intitialize cumulative m_counts
601  float* cum_counts = cum_his->GetCounts();
602  int i = 0;
603  for(i=0; i < res; i++)
604  cum_counts[i] = 0;
605 
606  cum_counts[0] = density_counts[0];
607  for(i = 1; i < res; i++)
608  {
609  cum_counts[i] += (density_counts[i] + cum_counts[i-1]);
610  }
611 
612  return cum_his;
613 }
int GetRes() const
float * GetCounts()

◆ deleteAll()

void ossimHistogram::deleteAll ( )
protectedvirtual

Definition at line 1286 of file ossimHistogram.cpp.

References m_counts, and m_vals.

Referenced by create(), and ~ossimHistogram().

1287 {
1288  if (m_vals)
1289  {
1290  delete []m_vals;
1291  m_vals = NULL;
1292  }
1293  if (m_counts)
1294  {
1295  delete []m_counts;
1296  m_counts = NULL;
1297  }
1298 }

◆ Dump()

void ossimHistogram::Dump ( char *  dumpfile) const

Definition at line 1248 of file ossimHistogram.cpp.

References m_counts, m_num, and m_vals.

1249 {
1250  FILE *dumpfp = fopen(dumpfile, "w");
1251 
1252  if (!dumpfp)
1253  {
1254  fprintf(stderr, "Error opening histogram data file.\n");
1255  return;
1256  }
1257  int i = 0;
1258 
1259  for(i = 0; i < m_num; i++)
1260  fprintf(dumpfp, "%f %f\n", m_vals[i], m_counts[i]);
1261 
1262  fclose(dumpfp);
1263  return;
1264 }

◆ fillInteriorEmptyBins()

ossimHistogram * ossimHistogram::fillInteriorEmptyBins ( int  type = HISTOGRAM_FILL_THIN_PLATE) const

Definition at line 442 of file ossimHistogram.cpp.

References ossimThinPlateSpline::addPoint(), GetCounts(), ossimThinPlateSpline::getPoint(), HISTOGRAM_FILL_DEFAULT, HISTOGRAM_FILL_THIN_PLATE, m_num, m_statsConsistent, ossimHistogram(), and ossimThinPlateSpline::solve().

443 {
444  if(m_num < 1) return 0;
445  ossimHistogram* result = new ossimHistogram(*this);
446  switch(type)
447  {
450  {
451  ossimThinPlateSpline spline(1);
452  double pvars[1];
453  float* new_counts = result->GetCounts();
454  ossim_int32 idxLeft = 0;
455  ossim_int32 idxRight = m_num-1;
456  while((idxLeft < m_num) && (new_counts[idxLeft] < 1))++idxLeft;
457  while((idxRight > -1) && (new_counts[idxRight] < 1))--idxRight;
458  if(idxLeft < idxRight)
459  {
460  ossim_int32 idx = idxLeft;
461  while(idx <= idxRight)
462  {
463  if(new_counts[idx]>0)
464  {
465  pvars[0] = new_counts[idx];
466  spline.addPoint(idx, 0, pvars);
467  }
468  ++idx;
469  }
470  if(spline.solve())
471  {
472  idx = idxLeft;
473  while(idx <= idxRight)
474  {
475  if(spline.getPoint(idx, 0, pvars))
476  {
477  new_counts[idx] = pvars[0];
478  }
479  ++idx;
480  }
481  m_statsConsistent = 0;
482  }
483  else
484  {
485  }
486  }
487 
488  break;
489  }
490  }
491 
492  return result;
493 }
float * GetCounts()
int ossim_int32

◆ GetBucketSize()

float ossimHistogram::GetBucketSize ( ) const
inline

Definition at line 149 of file ossimHistogram.h.

Referenced by ossimHistogram(), and Print().

149 { return m_delta; }

◆ GetCount()

float ossimHistogram::GetCount ( float  uval) const

Definition at line 971 of file ossimHistogram.cpp.

References GetIndex(), and m_counts.

972 {
973  int index = GetIndex(pixelval);
974 
975  if (index < 0)
976  return -1;
977  else
978  return m_counts[index];
979 }
virtual int GetIndex(float) const

◆ GetCounts() [1/2]

float* ossimHistogram::GetCounts ( )
inline

◆ GetCounts() [2/2]

const float* ossimHistogram::GetCounts ( ) const
inline

Definition at line 140 of file ossimHistogram.h.

141  {
142  //m_statsConsistent = 0; // m_counts might change.
143  return m_counts;
144  }

◆ getHighFractionFromValue()

float ossimHistogram::getHighFractionFromValue ( float  val) const

Returns the fraction of accumulation down to and including "val" bucket from max divided by the total accumulation. returns OSSIM_FLT_NAN if "val" is not between GetMin() and GetMax().

Definition at line 1133 of file ossimHistogram.cpp.

References GetMaxVal(), GetMinVal(), GetRes(), GetValIndex(), m_counts, and ossim::nan().

Referenced by ossimHistogramRemapper::setHighClipPoint().

1134 {
1135 // float min = floor(GetMinVal());
1136 // float max = ceil(GetMaxVal());
1137  float minValue = GetMinVal();
1138  float maxValue = GetMaxVal();
1139  if (val < minValue || val > maxValue)
1140  {
1141  return ossim::nan();
1142  }
1143 
1144  int total_buckets = GetRes();
1145  int cutoff_bucket = GetValIndex(val);
1146  float partial_sum = 0.0;
1147  float total_sum = 0.0;
1148 
1149  for(int i = (total_buckets-1); i >= 0; --i)
1150  {
1151  total_sum += m_counts[i];
1152  if (i >= cutoff_bucket)
1153  {
1154  partial_sum += m_counts[i];
1155  }
1156  }
1157 
1158  return (partial_sum/total_sum);
1159 }
int GetValIndex(float val) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
int GetRes() const
float GetMinVal() const
float GetMaxVal() const

◆ GetIndex()

int ossimHistogram::GetIndex ( float  pixelval) const
virtual

Definition at line 865 of file ossimHistogram.cpp.

References GetRes(), m_delta, m_num, m_vals, m_vmax, and m_vmin.

Referenced by ComputeArea(), GetCount(), ossimHistogramEqualization::initializeLuts(), ossimHistogramEqualization::runEqualizationAlgorithm(), Scale(), SetCount(), and UpCount().

866 {
867 #if 1
868  if ((pixelval > m_vmax) || (pixelval < m_vmin) || (m_num==0) )
869  {
870  return -1;
871  }
872 // ossim_float32 d = m_vmax-m_vmin;
873  int bandIdx = (ossim_int32)((pixelval-m_vmin)/m_delta);
874  return bandIdx<GetRes()?bandIdx:-1;
875 // if(bandIdx == m_num)
876 // {
877 // return m_num-1;
878 // }
879 // else if(bandIdx < m_num)
880 // {
881 // return bandIdx;
882 // }
883 // return -1;
884 #else
885  if ((pixelval > m_vmax) || (pixelval < m_vmin))
886  return -1;
887 
888  int idx = 0;
889  int i = 0;
890 
891  for(i = 0; i < m_num; i++)
892  {
893  //std::cout << std::setprecision(15) << m_vals[i] << std::endl;
894  // RWMC: This is very dangerous - might get an intermediate
895  // value which is between m_vals[i]+0.5*m_delta and
896  // m_vals[i+1]-0.5*m_delta, which would then return index of 0.
897  // Changed to check range one-sided, which is safe because of
898  // previous check on range.
899  // if ((pixelval > (m_vals[i] - 0.5 * m_delta)) &&
900  // (pixelval <= (m_vals[i] + 0.5 * m_delta)))
901  if (pixelval <= (m_vals[i] + 0.5 * m_delta))
902  {
903  idx = i;
904  break;
905  }
906  }
907 //std::cout << idx << std::endl;
908  return idx;
909 #endif
910 }
int GetRes() const
int ossim_int32

◆ getLowFractionFromValue()

float ossimHistogram::getLowFractionFromValue ( float  val) const

Returns the fraction of accumulation up to and including "val" bucket from min divided by the total accumulation. returns OSSIM_FLT_NAN if "val" is not between GetMinVal and GetMaxVal.

Definition at line 1102 of file ossimHistogram.cpp.

References GetMaxVal(), GetMinVal(), GetRes(), GetValIndex(), m_counts, and ossim::nan().

Referenced by ossimHistogramRemapper::setLowClipPoint().

1103 {
1104  // std::cout << "ossimHistogram::getLowFractionFromValue(float val)\n";
1105 // float minValue = floor(GetMinVal());
1106 // float maxValue = ceil(GetMaxVal());
1107  float minValue = GetMinVal();
1108  float maxValue = GetMaxVal();
1109  if (val < minValue || val > maxValue)
1110  {
1111  return ossim::nan();
1112  }
1113 // std::cout << "VAL: " << val << "\n"
1114 // << "MIN: " << minValue << "\n"
1115 // << "MAX: " << maxValue << "\n";
1116  int total_buckets = GetRes();
1117  int cutoff_bucket = GetValIndex(val);
1118  float partial_sum = 0.0;
1119  float total_sum = 0.0;
1120  // std::cout << "CUTOFF BUCKET ===" << cutoff_bucket << "\n";
1121  for(int i = 0; i < total_buckets; ++i)
1122  {
1123  total_sum += m_counts[i];
1124  if (i <= cutoff_bucket)
1125  {
1126  partial_sum += m_counts[i];
1127  }
1128  }
1129  // std::cout << "FRACTION ==== " << (partial_sum/total_sum) << "\n";
1130  return (partial_sum/total_sum);
1131 }
int GetValIndex(float val) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
int GetRes() const
float GetMinVal() const
float GetMaxVal() const

◆ GetMaxCount()

float ossimHistogram::GetMaxCount ( ) const

Definition at line 1010 of file ossimHistogram.cpp.

References m_counts, m_num, and max.

Referenced by ossimHistogramEqualization::initializeLuts().

1011 {
1012  int i=0;
1013  float max;
1014  max = 0.0;
1015  for (i=0; i < m_num; i++)
1016  if (m_counts[i] > max)
1017  max = m_counts[i];
1018  return max;
1019 }
#define max(a, b)
Definition: auxiliary.h:76

◆ GetMaxVal()

float ossimHistogram::GetMaxVal ( ) const

Definition at line 996 of file ossimHistogram.cpp.

References m_counts, m_num, and m_vals.

Referenced by ComputeArea(), getHighFractionFromValue(), getLowFractionFromValue(), HighClipVal(), LowClipVal(), ossimHistogram(), and Print().

997 {
998  int i=m_num-1;
999 
1000  while (i>0 && !m_counts[i])
1001  i--;
1002 
1003  if (i < 0)
1004  return 0.0;
1005 
1006  return m_vals[i];
1007 }

◆ GetMaxValFromIndex()

float ossimHistogram::GetMaxValFromIndex ( ossim_uint32  idx) const

Definition at line 924 of file ossimHistogram.cpp.

References m_delta, m_num, m_vals, and m_vmax.

925 {
926  float result = 0.0;
927 
928  if((int)idx < m_num)
929  {
930  result = (m_vals[idx]+(0.5 * m_delta));
931  if(result > m_vmax) result = m_vmax;
932  }
933 
934  return result;
935 }

◆ GetMean()

float ossimHistogram::GetMean ( ) const

Definition at line 802 of file ossimHistogram.cpp.

Referenced by ossimHistogram(), and Scale().

803 {
804  float xsum = 0.0;
805 
806  if(MEAN_FLAG&m_statsConsistent)
807  return m_mean;
808  else
809  {
810  if( this->GetBucketSize() > 0.0){
811  for(float x=this->GetMinVal(); x<= this->GetMaxVal(); x +=this->GetBucketSize())
812  xsum += x*GetCount(x);
813  }
814 
815  float area = ComputeArea(m_vmin, m_vmax);
816  if(area <= 0.0)
817  {
818  // fprintf(stderr, "Histogram : Area <= 0.0\n");
819  return 0.0;
820  }
821  else
822  {
823  m_statsConsistent |=1;
824  m_mean = xsum/area;
825  return m_mean;
826  }
827  }
828 }
ossim_uint32 x
float GetCount(float uval) const
float GetBucketSize() const
float GetMinVal() const
float ComputeArea() const
float GetMaxVal() const

◆ GetMinCountAddr() [1/2]

float* ossimHistogram::GetMinCountAddr ( )
inline

Definition at line 154 of file ossimHistogram.h.

155  { return m_counts+GetIndex(GetMinVal()); }
virtual int GetIndex(float) const
float GetMinVal() const

◆ GetMinCountAddr() [2/2]

const float* ossimHistogram::GetMinCountAddr ( ) const
inline

Definition at line 160 of file ossimHistogram.h.

161  { return m_counts+GetIndex(GetMinVal()); }
virtual int GetIndex(float) const
float GetMinVal() const

◆ GetMinVal()

float ossimHistogram::GetMinVal ( ) const

Definition at line 983 of file ossimHistogram.cpp.

References m_counts, m_num, and m_vals.

Referenced by ComputeArea(), getHighFractionFromValue(), getLowFractionFromValue(), HighClipVal(), LowClipVal(), ossimHistogram(), and Print().

984 {
985  int i=0;
986 
987  while (i<m_num-1 && !m_counts[i])
988  i++;
989 
990  return m_vals[i];
991 }

◆ GetMinValAddr() [1/2]

float* ossimHistogram::GetMinValAddr ( )
inline

Definition at line 151 of file ossimHistogram.h.

152  { return m_vals+GetIndex(GetMinVal()); }
virtual int GetIndex(float) const
float GetMinVal() const

◆ GetMinValAddr() [2/2]

const float* ossimHistogram::GetMinValAddr ( ) const
inline

Definition at line 157 of file ossimHistogram.h.

158  { return m_vals+GetIndex(GetMinVal()); }
virtual int GetIndex(float) const
float GetMinVal() const

◆ GetMinValFromIndex()

float ossimHistogram::GetMinValFromIndex ( ossim_uint32  idx) const

Definition at line 911 of file ossimHistogram.cpp.

References m_delta, m_num, m_vals, and m_vmin.

912 {
913  float result = 0.0;
914 
915  if((int)idx < m_num)
916  {
917  result = (m_vals[idx]-(0.5 * m_delta));
918  if(result < m_vmin) result = m_vmin;
919  }
920 
921  return result;
922 }

◆ GetRangeMax()

float ossimHistogram::GetRangeMax ( ) const
inline

Definition at line 119 of file ossimHistogram.h.

Referenced by ossimKMeansFilter::initialize(), and ossimHistogramEqualization::initializeLuts().

120  {
121  return m_vmax;
122  }

◆ GetRangeMin()

float ossimHistogram::GetRangeMin ( ) const
inline

Definition at line 115 of file ossimHistogram.h.

Referenced by ossimKMeansFilter::initialize(), and ossimHistogramEqualization::initializeLuts().

116  {
117  return m_vmin;
118  }

◆ GetRes()

int ossimHistogram::GetRes ( ) const
inline

◆ GetStandardDev()

float ossimHistogram::GetStandardDev ( ) const

Definition at line 832 of file ossimHistogram.cpp.

Referenced by ossimHistogram(), and Scale().

833 {
834  float sum = 0.0;
835 
836  if(SD_FLAG&m_statsConsistent)
837  return m_standardDev;
838  else
839  {
840  float xm = this -> GetMean(); // Force an Update of m_mean
841 
842  if( this->GetBucketSize() > 0.0){
843  for(float x=this->GetMinVal();
844  x<= this->GetMaxVal();
845  x +=this->GetBucketSize())
846 
847  sum += (x-xm)*(x-xm)*GetCount(x);
848  }
849 
850  float area = ComputeArea(m_vmin, m_vmax);
851  if(area <= 0.0)
852  {
853  // fprintf(stderr, "Histogram : Area <= 0.0\n");
854  return 0.0;
855  }
856  else
857  {
858  m_statsConsistent |= 2;
859  m_standardDev = (float)sqrt(sum/area);
860  return m_standardDev;
861  }
862  }
863 }
ossim_uint32 x
float GetCount(float uval) const
float GetBucketSize() const
float GetMean() const
float GetMinVal() const
float ComputeArea() const
float GetMaxVal() const

◆ GetValFromIndex()

float ossimHistogram::GetValFromIndex ( ossim_uint32  idx) const

Definition at line 937 of file ossimHistogram.cpp.

References m_num, and m_vals.

938 {
939  float result = 0.0;
940  if((int)idx < m_num)
941  {
942  result = m_vals[idx];
943  }
944 
945  return result;
946 }

◆ GetValIndex()

int ossimHistogram::GetValIndex ( float  val) const

Definition at line 948 of file ossimHistogram.cpp.

References m_delta, m_num, m_vals, m_vmax, and m_vmin.

Referenced by getHighFractionFromValue(), and getLowFractionFromValue().

949 {
950  if ((pixelval > m_vmax) || (pixelval < m_vmin))
951  return -1;
952 
953  int idx = 0;
954  int i = 0;
955 
956  for(i = 0; i < m_num; i++)
957  {
958  if ((pixelval > (m_vals[i] - 0.5 * m_delta)) &&
959  (pixelval <= (m_vals[i] + 0.5 * m_delta)))
960  {
961  idx = i;
962  break;
963  }
964  }
965 
966  return idx;
967 }

◆ GetVals() [1/2]

float* ossimHistogram::GetVals ( )
inline

Definition at line 123 of file ossimHistogram.h.

Referenced by ossimShorelineTool::autoComputeThreshold(), ossimKMeansFilter::computeKMeans(), HighClipVal(), LowClipVal(), ossimHistogram(), and Print().

124  {
125  m_statsConsistent = 0; // Values might change.
126  return m_vals;
127  }

◆ GetVals() [2/2]

const float* ossimHistogram::GetVals ( ) const
inline

Definition at line 128 of file ossimHistogram.h.

129  {
130  m_statsConsistent = 0; // Values might change.
131  return m_vals;
132  }

◆ HighClipVal()

float ossimHistogram::HighClipVal ( float  clip_fraction) const

Definition at line 1194 of file ossimHistogram.cpp.

References ComputeArea(), GetCounts(), GetMaxVal(), GetMinVal(), GetRes(), GetVals(), m_counts, and m_vals.

Referenced by ossimHistogramRemapper::getHighClipPoint(), ossimMultiBandHistogramTileSource::runLinearStretchAlgorithm(), and ossimHistogramThreshholdFilter::runThreshholdStretchAlgorithm().

1195 {
1196  if(clip_fraction<0) clip_fraction=0.0;
1197  if(clip_fraction>1.0) clip_fraction=1.0;
1198  float area = this->ComputeArea();
1199  if(area==0.0) return this->GetMaxVal();
1200  if(clip_fraction==0.0) return this->GetMaxVal();
1201  if(clip_fraction==1.0) return this->GetMinVal();
1202  float clip_area = area*clip_fraction;
1203  const float* m_counts = this->GetCounts();
1204  const float* m_vals = this->GetVals();
1205  int res = this->GetRes();
1206  float sum = 0;
1207  int i = (res-1);
1208  for(; i>=0; i--)
1209  {
1210  sum+=m_counts[i];
1211  if(sum>=clip_area)
1212  break;
1213  }
1214  return m_vals[i];
1215 }
int GetRes() const
float GetMinVal() const
float * GetCounts()
float ComputeArea() const
float * GetVals()
float GetMaxVal() const

◆ importHistogram() [1/2]

bool ossimHistogram::importHistogram ( const ossimFilename inputFile)
virtual

Definition at line 1352 of file ossimHistogram.cpp.

References ossimString::c_str(), and ossimFilename::exists().

Referenced by ossimMultiBandHistogram::importHistogram().

1353 {
1354  if(inputFile.exists())
1355  {
1356  ifstream input(inputFile.c_str());
1357 
1358  return importHistogram(input);
1359  }
1360 
1361  return false;
1362 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool exists() const
virtual bool importHistogram(const ossimFilename &inputFile)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396

◆ importHistogram() [2/2]

bool ossimHistogram::importHistogram ( istream &  in)
virtual

Definition at line 1306 of file ossimHistogram.cpp.

References ossimString::c_str(), create(), getline(), ossimHistogram::ossimProprietaryHeaderInformation::getNumberOfBins(), ossimHistogram::ossimProprietaryHeaderInformation::parseStream(), SetCount(), and ossimString::toDouble().

1307 {
1308  ossimProprietaryHeaderInformation header;
1309  bool binsCreated = false;
1310 
1311  if(header.parseStream(in))
1312  {
1313  long numberOfBins = header.getNumberOfBins();
1314 
1315  if(numberOfBins)
1316  {
1317  create(numberOfBins, 0, numberOfBins - 1);
1318  binsCreated = true;
1319 
1320  if(binsCreated)
1321  {
1322  ossimString buffer;
1323  ossimString binNumber;
1324  ossimString count;
1325 
1326  while(in.good() &&
1327  !in.eof() &&
1328  *binNumber.c_str() != '.')
1329  {
1330 
1331  getline(in, buffer);
1332 
1333  istringstream s(buffer);
1334 
1335  s >> binNumber >> count;
1336  if(*binNumber.c_str() != (char)'.')
1337  {
1338  SetCount((float)binNumber.toDouble(),
1339  (float)count.toDouble());
1340  }
1341  }
1342  }
1343  }
1344  else
1345  {
1346  return false;
1347  }
1348  }
1349  return true;
1350 }
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
void create(int xres, float val1, float val2)
double toDouble() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
float SetCount(float pixelval, float count)

◆ loadState() [1/2]

bool ossimHistogram::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Method to the load (recreate) the state of the object from a keyword list. Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 1514 of file ossimHistogram.cpp.

References create(), ossimString::empty(), ossimKeywordlist::extractKeysThatMatch(), ossimKeywordlist::find(), GetCounts(), ossimKeywordlist::getMap(), ossimKeywordlist::getSubstringKeyList(), size, ossimString::toDouble(), ossimString::toString(), ossimString::toUInt32(), and ossim::toVector().

Referenced by ossimMultiBandHistogram::loadState().

1516 {
1517 // std::cout << "ossimHistogram::loadState!!!!\n";
1518  const char* number_of_bins = kwl.find(prefix, "number_of_bins");
1519 
1520 // std::cout << "NBINS = " << number_of_bins << std::endl;
1521  if(number_of_bins)
1522  {
1523  ossim_uint32 bins = ossimString(number_of_bins).toUInt32();
1524 
1525 // std::cout << "BINS ======== " << bins << std::endl;
1526  if(bins > 0)
1527  {
1528  // setup some defaults
1529  float minValue = 0;
1530  float maxValue = bins - 1;
1531 
1532  // see if there is a range set for the data
1533  const char* min_value = kwl.find(prefix, "min_value");
1534  const char* max_value = kwl.find(prefix, "max_value");
1535 
1536  if(min_value)
1537  {
1538  minValue = (ossim_float32)ossimString(min_value).toDouble();
1539  }
1540  if(max_value)
1541  {
1542  maxValue = (ossim_float32)ossimString(max_value).toDouble();
1543  }
1544 
1545  create((int)bins, minValue, maxValue);
1546  float* countsPtr = GetCounts();
1547  memset(countsPtr, '\0', bins*sizeof(float));
1548  // this is new style histogram creation
1549  //
1550  ossimString binsString = kwl.find(prefix, "bins");
1551  if(!binsString.empty())
1552  {
1553  std::vector<ossimDpt> result;
1554  ossim::toVector(result, binsString);
1555  if(!result.empty())
1556  {
1557  ossim_uint32 idx = 0;
1558  for(idx = 0; idx < result.size();++idx)
1559  {
1560  ossim_uint32 binIdx = static_cast<ossim_uint32>(result[idx].x);
1561  if(binIdx < bins)
1562  {
1563  countsPtr[binIdx] = result[idx].y;
1564  }
1565  }
1566  }
1567  }
1568  else
1569  {
1570  ossimKeywordlist binsKwl;
1571  ossim_uint32 offset = (ossim_uint32)(ossimString(prefix)+"bin").size();
1572  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "bin[0-9]+)";
1573  kwl.extractKeysThatMatch(binsKwl,regExpression);
1574  const ossimKeywordlist::KeywordMap& kwlMap = binsKwl.getMap();
1575  ossimKeywordlist::KeywordMap::const_iterator iter = kwlMap.begin();
1576  while(iter != kwlMap.end())
1577  {
1578  ossimString numberStr(iter->first.begin() + offset,
1579  iter->first.end());
1580  countsPtr[numberStr.toUInt32()] = ossimString(iter->second).toDouble();
1581  ++iter;
1582  }
1583  }
1584 
1585 // ossimKeywordlist kwl;
1586 // this->saveState(kwl);
1587 // std::cout << kwl << std::endl;
1588 
1589  return true;
1590 #if 0
1591  // create the bins
1592  ossimString binNumber = "";
1593  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "bin[0-9]+)";
1594  vector<ossimString> keys = kwl.getSubstringKeyList( regExpression );
1595  ossim_uint32 numberOfBins = (ossim_uint32)keys.size();
1596  ossim_uint32 offset = (ossim_uint32)(ossimString(prefix)+"bin").size();
1597 
1598  std::vector<ossim_uint32> theNumberList(numberOfBins);
1599  ossim_uint32 idx = 0;
1600  for(idx = 0; idx < theNumberList.size();++idx)
1601  {
1602  ossimString numberStr(keys[idx].begin() + offset,
1603  keys[idx].end());
1604  theNumberList[idx] = numberStr.toUInt32();
1605 
1606  }
1607 
1608  float* countsPtr = GetCounts();
1609  memset(countsPtr, '\0', bins*sizeof(float));
1610  for(idx = 0; idx < numberOfBins;++idx)
1611  {
1612  const char* binCount = kwl.find(prefix, ossimString("bin") + ossimString::toString(theNumberList[idx]));
1613  countsPtr[theNumberList[idx]] = (float)ossimString(binCount).toDouble();
1614  }
1615 #endif
1616  }
1617  }
1618  return true;
1619 }
Represents serializable keyword/value map.
const char * find(const char *key) const
float ossim_float32
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_uint32 toUInt32() const
OSSIM_DLL void toVector(std::vector< ossimDpt > &result, const ossimString &stringOfPoints)
Will take a string list separated by spaces and convert to a vector of ossimDpts. ...
yy_size_t size
std::map< std::string, std::string > KeywordMap
unsigned int ossim_uint32
void create(int xres, float val1, float val2)
double toDouble() const
void extractKeysThatMatch(ossimKeywordlist &kwl, const ossimString &regularExpression) const
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
const ossimKeywordlist::KeywordMap & getMap() const
float * GetCounts()
bool empty() const
Definition: ossimString.h:411

◆ loadState() [2/2]

bool ossimHistogram::loadState ( const ossimRefPtr< ossimXmlNode xmlNode)
virtual

Definition at line 1621 of file ossimHistogram.cpp.

References create(), ossimXmlNode::findFirstNode(), GetCounts(), ossimXmlNode::getText(), ossimString::push_back(), ossimString::toFloat32(), and ossimRefPtr< T >::valid().

1622 {
1623  ossimRefPtr<ossimXmlNode> binValues = xmlNode->findFirstNode("binValues");
1624  ossimRefPtr<ossimXmlNode> minValueNode = xmlNode->findFirstNode("minValue");
1625  ossimRefPtr<ossimXmlNode> maxValueNode = xmlNode->findFirstNode("maxValue");
1626 
1627  if(binValues.valid())
1628  {
1629  ossim_uint32 count = 0;
1630  float minValue = 0.0;
1631  float maxValue = 0.0;
1632  std::vector<float> floatValues;
1633  std::istringstream in(binValues->getText());
1634  ossimString vString;
1635  while(!in.fail())
1636  {
1637  in>>vString;
1638  if(!in.fail())
1639  {
1640  floatValues.push_back(vString.toFloat32());
1641  }
1642  }
1643  count = (ossim_uint32)floatValues.size();
1644 
1645  if(count)
1646  {
1647  minValue = 0;
1648  maxValue = count - 1;
1649 
1650  if(minValueNode.valid())
1651  {
1652  minValue = minValueNode->getText().toFloat32();
1653  }
1654  if(maxValueNode.valid())
1655  {
1656  maxValue = maxValueNode->getText().toFloat32();
1657  }
1658 
1659  create(count, minValue, maxValue);
1660  float* countsPtr = GetCounts();
1661  ossim_uint32 idx = 0;
1662  for(idx = 0; idx < count; ++idx)
1663  {
1664  countsPtr[idx] = floatValues[idx];
1665  }
1666  return true;
1667  }
1668  }
1669 
1670  return false;
1671 }
bool valid() const
Definition: ossimRefPtr.h:75
const ossimRefPtr< ossimXmlNode > & findFirstNode(const ossimString &rel_xpath) const
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
const ossimString & getText() const
Definition: ossimXmlNode.h:92
unsigned int ossim_uint32
void create(int xres, float val1, float val2)
ossim_float32 toFloat32() const
float * GetCounts()
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32

◆ LowClipVal()

float ossimHistogram::LowClipVal ( float  clip_fraction) const

Definition at line 1165 of file ossimHistogram.cpp.

References ComputeArea(), GetCounts(), GetMaxVal(), GetMinVal(), GetRes(), GetVals(), m_counts, and m_vals.

Referenced by ossimHistogramRemapper::getLowClipPoint(), ossimMultiBandHistogramTileSource::runLinearStretchAlgorithm(), and ossimHistogramThreshholdFilter::runThreshholdStretchAlgorithm().

1166 {
1167  if(clip_fraction<0) clip_fraction=0.0;
1168  if(clip_fraction>1.0) clip_fraction=1.0;
1169  float area = this->ComputeArea();
1170  if(area==0.0) return this->GetMinVal();
1171  if(clip_fraction==0.0) return this->GetMinVal();
1172  if(clip_fraction==1.0) return this->GetMaxVal();
1173  float clip_area = area*clip_fraction;
1174  const float* m_counts = this->GetCounts();
1175  const float* m_vals = this->GetVals();
1176  int res = this->GetRes();
1177  float sum = 0;
1178  int i=0;
1179 
1180  for(; i<res; i++)
1181  {
1182  sum+=m_counts[i];
1183  if(sum>=clip_area)
1184  break;
1185  }
1186 
1187  return m_vals[i];
1188 }
int GetRes() const
float GetMinVal() const
float * GetCounts()
float ComputeArea() const
float * GetVals()
float GetMaxVal() const

◆ NonMaximumSupress()

ossimHistogram * ossimHistogram::NonMaximumSupress ( int  radius = 1,
bool  cyclic = false 
)

Definition at line 762 of file ossimHistogram.cpp.

References GetCounts(), GetExtendedCount(), GetRes(), m_num, ossimHistogram(), ossimNotify(), ossimNotifyLevel_WARN, and RemoveFlatPeaks().

763 {
764  if((2*radius +1)> m_num/2)
765  {
766  ossimNotify(ossimNotifyLevel_WARN)<<"ossimHistogram::NonMaximumSupress the radius is too large \n";
767  return NULL;
768  }
769  //Get the m_counts array of "this"
770  ossimHistogram* h_new = new ossimHistogram(*this);
771  int n_buckets = h_new->GetRes();
772  float* counts_old = this->GetCounts();
773 
774  //Make a new Histogram for the suppressed version
775  float* counts_new = h_new->GetCounts();
776  int i;
777  for( i =0; i < n_buckets; i++)
778  counts_new[i] = 0;
779 
780  //Find local maxima
781  for( i = 0; i< n_buckets; i++)
782  {
783  //find the maxium value in the current kernel
784  float max_count = counts_old[i];
785  int k = 0;
786  for(k = -radius; k <= radius ;k++)
787  {
788  int index = i+k;
789  float c = GetExtendedCount(index, n_buckets, counts_old, cyclic);
790  if( c > max_count)
791  max_count = c;
792  }
793  //Is position i a local maxium?
794  if(max_count == counts_old[i])
795  counts_new[i] = max_count;//Yes. So set the m_counts to the max value
796  }
797  RemoveFlatPeaks(n_buckets, counts_new, cyclic);
798  return h_new;
799 }
int GetRes() const
void RemoveFlatPeaks(int nbins, float *cnts, bool cyclic)
float * GetCounts()
float GetExtendedCount(int bin, int n_bins, float *cnts, bool cyclic)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ Print()

void ossimHistogram::Print ( ) const

Definition at line 1219 of file ossimHistogram.cpp.

References ComputeArea(), GetBucketSize(), GetCounts(), GetMaxVal(), GetMinVal(), GetRes(), GetVals(), m_counts, m_vals, ossimNotify(), and ossimNotifyLevel_INFO.

1220 {
1222  const float* m_vals = this->GetVals();
1223  const float* m_counts = this->GetCounts();
1224  int res = this->GetRes();
1225  int width = 0;
1226  int i = 0;
1227  for(i =0; i < res; i++)
1228  {
1229  if(width++ > 5)
1230  {
1231  width = 0;
1232  out << "\n";
1233  }
1234  out << m_vals[i] << " " << m_counts[i] << " | " ;
1235  }
1236  out << "\n MaxVal " << this->GetMaxVal() << "\n";
1237  out << " MinVal " << this->GetMinVal() << "\n";
1238  out << " BucketSize " << this->GetBucketSize() << "\n";
1239  out << " Resolution " << this->GetRes() << "\n";
1240  out << " Area "
1241  << this->ComputeArea(this->GetMinVal(),this->GetMaxVal()) << "\n";
1242  out << "------------------------------------------------\n\n";
1243 }
float GetBucketSize() const
int GetRes() const
float GetMinVal() const
float * GetCounts()
float ComputeArea() const
float * GetVals()
float GetMaxVal() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23

◆ saveState() [1/2]

bool ossimHistogram::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const
virtual

Method to save the state of the object to a keyword list. Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 1449 of file ossimHistogram.cpp.

References ossimKeywordlist::add(), ossimString::c_str(), FLT_EPSILON, m_counts, m_num, m_vmax, m_vmin, and ossimString::toString().

1451 {
1452  kwl.add(prefix,
1453  "type",
1454  "ossimHistogram",
1455  true);
1456  kwl.add(prefix,
1457  "number_of_bins",
1458  m_num,
1459  true);
1460  kwl.add(prefix,
1461  "min_value",
1462  m_vmin,
1463  true);
1464  kwl.add(prefix,
1465  "max_value",
1466  m_vmax,
1467  true);
1468 
1469 
1470 
1471  ossimString binArrayList = "(";
1472  bool firstValue = true;
1473 
1474  for(ossim_int32 index = 0; index < m_num; ++index)
1475  {
1476  if(fabs(m_counts[index]) > FLT_EPSILON)
1477  {
1478 
1479  if(!firstValue)
1480  {
1481  binArrayList += ",";
1482  }
1483  else
1484  {
1485  firstValue = false;
1486  }
1487  binArrayList += "("+ossimString::toString(index)+","+ossimString::toString(m_counts[index])+")";
1488  }
1489  }
1490 
1491  binArrayList += ")";
1492 
1493  kwl.add(prefix, "bins", binArrayList, true);
1494 #if 0
1495  ossimString binValue = "";
1496  for(ossim_int32 index = 0; index < m_num; ++index)
1497  {
1498  if(fabs(m_counts[index]) > FLT_EPSILON)
1499  {
1500  // binValue = prefix;
1501  binValue = "bin";
1502  binValue += ossimString::toString(index);
1503 
1504  kwl.add(prefix,
1505  binValue.c_str(),
1506  m_counts[index],
1507  true);
1508  }
1509  }
1510 #endif
1511  return true;
1512 }
static ossimString toString(bool aValue)
Numeric to string methods.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
#define FLT_EPSILON
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
int ossim_int32

◆ saveState() [2/2]

bool ossimHistogram::saveState ( ossimRefPtr< ossimXmlNode xmlNode) const
virtual

Definition at line 1673 of file ossimHistogram.cpp.

References ossimXmlNode::addChildNode(), ossimRefPtr< T >::get(), m_counts, m_mean, m_num, m_standardDev, m_vmax, m_vmin, ossimXmlNode::setTag(), ossimXmlNode::setText(), and ossimString::toString().

1674 {
1675  ossimRefPtr<ossimXmlNode> binValues = new ossimXmlNode;
1676  xmlNode->setTag("ossimHistogram");
1677  xmlNode->addChildNode("minValue", ossimString::toString(m_vmin));
1678  xmlNode->addChildNode("maxValue", ossimString::toString(m_vmax));
1679  xmlNode->addChildNode("standardDeviation", ossimString::toString(m_standardDev));
1680  xmlNode->addChildNode("m_mean", ossimString::toString(m_mean));
1681  binValues->setTag("binValues");
1682  std::ostringstream out;
1683 
1684  ossim_int32 idx = 0;
1685  if(m_num > 0)
1686  {
1687  for(idx = 0; idx < m_num;++idx)
1688  {
1689  out << ossimString::toString(m_counts[idx], 8) << " ";
1690  }
1691  binValues->setText(out.str());
1692  }
1693  xmlNode->addChildNode(binValues.get());
1694 
1695  return true;
1696 }
void setTag(const ossimString &tag)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
void setText(const ossimString &text)
static ossimString toString(bool aValue)
Numeric to string methods.
void addChildNode(ossimRefPtr< ossimXmlNode > node)
int ossim_int32

◆ Scale()

ossimHistogram * ossimHistogram::Scale ( float  scale_factor)

Definition at line 499 of file ossimHistogram.cpp.

References GetCounts(), GetIndex(), GetMean(), GetStandardDev(), m_counts, m_delta, m_mean, m_num, m_standardDev, m_vals, m_vmin, ossimHistogram(), and x.

500 {
501 
502 // Extract attributes of self
503 
504 // float lowvalue = m_vals[0];
505  float highvalue = m_vals[m_num-1];
506 
507 // Construct a new histogram
508 
509  ossimHistogram* scaled_his = new ossimHistogram(this, m_delta);
510  float* new_counts = scaled_his->GetCounts();
511  int i = 0;
512  for(i=0; i < m_num; i++) // Initialize
513  new_counts[i] = 0.0;
514 
515 // Compute scaled values
516 // We assume that the new histogram is to be scaled down from his
517 
518  float scale = scale_factor;
519  if(scale_factor > 1.0) scale = 1.0;
520 
521  for(float x = highvalue; x > m_vmin;)
522  {
523  float trans_x = (x-m_vmin)*scale + m_vmin; // Scaled x.
524  int index = GetIndex(trans_x);
525  if (index < 0)
526  {
527  if (trans_x<m_vmin) index = 0;
528  else index = m_num-1;
529  }
530  float fraction = (trans_x - m_vals[index])/m_delta;
531  float abs_fraction = (float)fabs(fraction);
532  int x_index = GetIndex(x);
533  if (x_index < 0)
534  {
535  if (x<m_vmin) x_index = 0;
536  else x_index = m_num-1;
537  }
538 
539 // Distribute the m_counts in proportion
540 
541  new_counts[index] += (1.0f - abs_fraction)*m_counts[x_index];
542  if(fraction > 0)
543  if(index < (m_num-1))
544  new_counts[index + 1] +=
545  abs_fraction*m_counts[x_index];
546  else
547  new_counts[index] +=
548  abs_fraction*m_counts[x_index];
549  else
550  if(index > 0)
551  new_counts[index - 1] +=
552  abs_fraction*m_counts[x_index];
553  else
554  new_counts[index] +=
555  abs_fraction*m_counts[x_index];
556  x -= m_delta;
557  }
558 
559 // Compute new Histogram attributes
560 
561  m_mean = scaled_his->GetMean();
562  m_standardDev = scaled_his->GetStandardDev();
563  return scaled_his;
564 }
ossim_uint32 x
float GetMean() const
float GetStandardDev() const
virtual int GetIndex(float) const
float * GetCounts()

◆ SetCount()

float ossimHistogram::SetCount ( float  pixelval,
float  count 
)

Definition at line 1024 of file ossimHistogram.cpp.

References GetIndex(), m_counts, and m_statsConsistent.

Referenced by importHistogram(), and ossimHistogramRemapper::setNullCount().

1025 {
1026  m_statsConsistent = 0;
1027 
1028  int index = GetIndex(pixelval);
1029 
1030  if (index < 0)
1031  return -1;
1032  else
1033  {
1034  m_counts[index] = count;
1035  return count;
1036  }
1037 }
virtual int GetIndex(float) const

◆ UpCount()

void ossimHistogram::UpCount ( float  newval,
float  occurences = 1 
)

Definition at line 1040 of file ossimHistogram.cpp.

References GetIndex(), m_counts, and m_statsConsistent.

Referenced by ossimHistogram(), and ossimImageData::populateHistogram().

1041 {
1042 
1043  m_statsConsistent = 0;
1044  int idx = GetIndex(pixelval);
1045  if (idx >= 0) // Originally (index > 0)
1046  {
1047  m_counts[idx] += occurences;
1048  }
1049 }
virtual int GetIndex(float) const

◆ WritePlot()

int ossimHistogram::WritePlot ( const char *  fname) const

Definition at line 1269 of file ossimHistogram.cpp.

References m_counts, m_num, and m_vals.

1270 {
1271  FILE *fp = fopen(fname, "w");
1272 
1273  if (!fp)
1274  {
1275  fprintf(stderr, "Error opening histogram plot file.\n");
1276  return 0;
1277  }
1278 
1279  for(int j = 0; j < m_num; j++)
1280  fprintf(fp, "%f %f\n", m_vals[j], m_counts[j]);
1281 
1282  fclose(fp);
1283  return 1;
1284 }

Member Data Documentation

◆ m_counts

float* ossimHistogram::m_counts
protected

◆ m_delta

float ossimHistogram::m_delta
protected

◆ m_mean

float ossimHistogram::m_mean
mutableprotected

Definition at line 49 of file ossimHistogram.h.

Referenced by create(), ossimHistogram(), saveState(), and Scale().

◆ m_num

int ossimHistogram::m_num
protected

◆ m_standardDev

float ossimHistogram::m_standardDev
mutableprotected

Definition at line 50 of file ossimHistogram.h.

Referenced by create(), ossimHistogram(), saveState(), and Scale().

◆ m_statsConsistent

int ossimHistogram::m_statsConsistent
mutableprivate

Definition at line 32 of file ossimHistogram.h.

Referenced by create(), fillInteriorEmptyBins(), ossimHistogram(), SetCount(), and UpCount().

◆ m_vals

float* ossimHistogram::m_vals
protected

◆ m_vmax

float ossimHistogram::m_vmax
protected

◆ m_vmin

float ossimHistogram::m_vmin
protected

The documentation for this class was generated from the following files: