OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHistogramThreshholdFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimHistogramThreshholdFilter.cpp 17195 2010-04-23 17:32:18Z dburken $
18 #include <ossim/base/ossimCommon.h>
21 
22 static const ossimKeyword MIN_VALUE_PERCENT_KW("min_percent",
23  "min percentage clip");
24 
25 static const ossimKeyword MAX_VALUE_PERCENT_KW("max_percent",
26  "max percentage value");
27 
28 
30 
33  theMinValuePercent(0.0),
34  theMaxValuePercent(0.0)
35 {
36 }
37 
39  double maxValuePercent,
40  ossimImageSource* inputSource,
41  ossimMultiResLevelHistogram* histogram)
42  : ossimImageSourceHistogramFilter(inputSource, histogram),
43  theMinValuePercent(minValuePercent),
44  theMaxValuePercent(maxValuePercent)
45 {
46 }
47 
49 {
50 }
51 
53  const ossimIrect& tileRect,
54  ossim_uint32 resLevel)
55 {
56  if(!theInputConnection) return NULL;
57 
58  ossimRefPtr<ossimImageData> inputTile =
59  theInputConnection->getTile(tileRect, resLevel);
60 
61  if(!isSourceEnabled())
62  {
63  return inputTile;
64  }
65  if(inputTile.valid() &&
66  inputTile->getBuf() &&
67  (inputTile->getDataObjectStatus()!=OSSIM_EMPTY))
68  {
69  switch(inputTile->getScalarType())
70  {
71  case OSSIM_UCHAR:
72  {
74  inputTile);
75  }
76  case OSSIM_USHORT16:
77  case OSSIM_USHORT11:
78  case OSSIM_USHORT12:
79  case OSSIM_USHORT13:
80  case OSSIM_USHORT14:
81  case OSSIM_USHORT15:
82  {
84  inputTile);
85  }
86  case OSSIM_SSHORT16:
87  {
88  return runThreshholdStretchAlgorithm(static_cast<ossim_sint16>(0),
89  inputTile);
90  }
91  case OSSIM_DOUBLE:
93  {
94  return runThreshholdStretchAlgorithm(static_cast<double>(0),
95  inputTile);
96  }
97  case OSSIM_FLOAT:
99  {
100  return runThreshholdStretchAlgorithm(static_cast<float>(0),
101  inputTile);
102  }
104  default:
105  {
106  ossimSetError("ossimHistogramThreshholdFilter",
108  "Unknown scalar type");
109  break;
110  }
111  }
112  }
113 
114  return inputTile;
115 }
116 
117 
119  const char* prefix)
120 {
122  {
123  const char* minPercent = kwl.find(prefix, MIN_VALUE_PERCENT_KW);
124  const char* maxPercent = kwl.find(prefix, MAX_VALUE_PERCENT_KW);
125 
126  if(minPercent)
127  {
128  theMinValuePercent = ossimString(minPercent).toDouble();
129  }
130  else
131  {
132  theMinValuePercent = 0.0;
133  }
134  if(maxPercent)
135  {
136  theMaxValuePercent = ossimString(maxPercent).toDouble();
137  }
138  else
139  {
140  theMaxValuePercent = 0.0;
141  }
142  }
143  else
144  {
145  return false;
146  }
147 
148  return true;
149 }
150 
152  const char* prefix)const
153 {
155  {
156  kwl.add(prefix,
157  MIN_VALUE_PERCENT_KW,
159  true);
160  kwl.add(prefix,
161  MAX_VALUE_PERCENT_KW,
163  true);
164  }
165  else
166  {
167  return false;
168  }
169 
170  return true;
171 }
172 
174 {
176 }
177 
178 template <class T>
180  T /* dummyVariable */,
182 {
183  if(!getHistogram())
184  {
185  return tile;
186  }
187 
189  if(histo.valid())
190  {
191  ossim_uint32 maxBands = ( (histo->getNumberOfBands() >
192  tile->getNumberOfBands())?
193  tile->getNumberOfBands():
194  histo->getNumberOfBands());
195 
196  long offsetUpperBound = tile->getHeight()*tile->getWidth();
197 
198  for(ossim_uint32 band = 0; band < maxBands; ++band)
199  {
200  ossimRefPtr<ossimHistogram> h = histo->getHistogram(band);
201  T* buf = static_cast<T*>(tile->getBuf(band));
202 
203  if(h.valid()&&buf)
204  {
205  T np = static_cast<T>(tile->getNullPix(band));
206  T minPix = static_cast<T>(tile->getMinPix(band));
207  T maxPix = static_cast<T>(tile->getMaxPix(band));
208  double range = (maxPix - minPix);
209  double res = h->GetRes();
210  double maxClip = (h->HighClipVal(theMaxValuePercent/100.0)/res);
211  double minClip = (h->LowClipVal(theMinValuePercent/100.0)/res);
212  ossim_float64 normPix;
213  double delta = fabs(maxClip - minClip);
214  if(delta > 0.0)
215  {
216  for(long offset = 0; offset < offsetUpperBound; ++offset)
217  {
218  if(buf[offset] != np)
219  {
220  normPix = ((double)buf[offset]-minPix)/range;
221  if(normPix <= minClip)
222  {
223  buf[offset] = minPix;
224  }
225  else if(normPix >= maxClip)
226  {
227  buf[offset] = maxPix;
228  }
229  else
230  {
231  double t = (normPix - minClip)/delta;
232  T value = static_cast<T>(minPix + range*t);
233  buf[offset] = value;
234  }
235  }
236  }
237  }
238  }
239  }
240 
241  tile->validate();
242  }
243 
244  return tile;
245 }
246 
248 {
249  theMinValuePercent = minValue;
250 }
251 
253 {
254  theMaxValuePercent = maxValue;
255 }
256 
258 {
259  return theMinValuePercent;
260 }
261 
263 {
264  return theMaxValuePercent;
265 }
OSSIMDLLEXPORT void ossimSetError(const char *className, ossim_int32 error, const char *fmtString=0,...)
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual const ossim_float64 * getMaxPix() const
virtual ossim_uint32 getNumberOfBands() const
Represents serializable keyword/value map.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
static const ossimErrorCode OSSIM_ERROR
16 bit unsigned integer (13 bits used)
unsigned short ossim_uint16
virtual ossimRefPtr< ossimMultiResLevelHistogram > getHistogram()
ossimRefPtr< ossimImageData > runThreshholdStretchAlgorithm(T dummyVariable, ossimRefPtr< ossimImageData > &tile)
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
int GetRes() const
virtual void setMinValuePercent(double minValue)
ossim_uint32 getNumberOfBands() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
ossimRefPtr< ossimHistogram > getHistogram(ossim_int32 band)
double toDouble() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
float HighClipVal(float clip_fraction) const
float LowClipVal(float clip_fraction) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
virtual const ossim_float64 * getMinPix() const
virtual ossimScalarType getScalarType() const
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
virtual void setMaxValuePercent(double maxValue)
virtual const void * getBuf() const
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
32 bit floating point
ossimRefPtr< ossimMultiBandHistogram > getMultiBandHistogram(ossim_uint32 resLevel) const
16 bit unsigned iteger
64 bit floating point
16 bit signed integer
unsigned char ossim_uint8
8 bit unsigned iteger
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)