OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimBrightnessMatch.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 // Description: A brief description of the contents of the file.
11 //
12 //*************************************************************************
13 // $Id: ossimBrightnessMatch.cpp 11955 2007-10-31 16:10:22Z gpotts $
14 
19 #include <ossim/base/ossimCommon.h>
21 #include <ossim/base/ossimTrace.h>
26 
28  "ossimBrightnessMatch",
30 
33  theTargetBrightness(0.5),
34  theInputBrightness(0.5)
35 {
36  theInputBrightness = ossim::nan();
37  theBrightnessContrastSource = new ossimBrightnessContrastSource;
38 }
39 
40 
42 {
43 }
44 
46  const ossimIrect& tileRect, ossim_uint32 resLevel)
47 {
48  if(!isSourceEnabled())
49  {
50  return ossimImageSourceFilter::getTile(tileRect, resLevel);
51  }
53  {
55  {
57  }
58  return theBrightnessContrastSource->getTile(tileRect, resLevel);
59  }
60  return 0;
61 }
62 
64 {
66  theNormTile = 0;
67 }
68 
70 {
71  if(!property)
72  {
73  return;
74  }
75  ossimString name = property->getName();
76  if(name == "input_brightness")
77  {
78  theInputBrightness = property->valueToString().toDouble();
80  }
81  else if(name == "target_brightness")
82  {
83  theTargetBrightness = property->valueToString().toDouble();
85  }
86  else
87  {
89  }
90 }
91 
93 {
94  if(name == "target_brightness")
95  {
96  ossimNumericProperty* numeric = new ossimNumericProperty(name,
98  0.0, 1.0);
100  numeric->setCacheRefreshBit();
101  return numeric;
102  }
103  else if(name == "input_brightness")
104  {
105  ossimNumericProperty* numeric = new ossimNumericProperty(name,
107  0.0, 1.0);
109  numeric->setCacheRefreshBit();
110  return numeric;
111  }
112 
114 }
115 
116 void ossimBrightnessMatch::getPropertyNames(std::vector<ossimString>& propertyNames)const
117 {
119 
120  propertyNames.push_back("input_brightness");
121  propertyNames.push_back("target_brightness");
122 }
123 
124 
126  const char* prefix)
127 {
128  const char* input_brightness = kwl.find(prefix, "input_brightness");
129  const char* target_brightness = kwl.find(prefix, "target_brightness");
130 
131  if(input_brightness)
132  {
133  theInputBrightness = ossimString(input_brightness).toDouble();
134  }
135  if(target_brightness)
136  {
137  theTargetBrightness = ossimString(target_brightness).toDouble();
138  }
139 
140  return ossimImageSourceFilter::loadState(kwl, prefix);
141 }
142 
144  const char* prefix)const
145 {
146  kwl.add(prefix,
147  "input_brightness",
149  true);
150  kwl.add(prefix,
151  "target_brightness",
153  true);
154 
155  return ossimImageSourceFilter::saveState(kwl, prefix);
156 }
157 
158 
160 {
162  {
163  ossimIrect inputRect = getBoundingRect();
164  ossim_uint32 rlevel = 0;
166  if(nlevels>1)
167  {
168  while((ossim::max(inputRect.width(), inputRect.height()) > 2048)&&
169  (rlevel < nlevels))
170  {
171  ++rlevel;
172  inputRect = getBoundingRect(rlevel);
173  }
174  }
175  ossimIpt centerPt = inputRect.midPoint();
176  centerPt.x -= 1024;
177  centerPt.y -= 1024;
178  ossimIrect reqRect(centerPt.x,
179  centerPt.y,
180  centerPt.x + 2047,
181  centerPt.x + 2047);
182  reqRect = reqRect.clipToRect(inputRect);
183  ossimRefPtr<ossimImageData> inputTile = theInputConnection->getTile(reqRect, rlevel);
184 
185  if(inputTile.valid())
186  {
187  theNormTile = new ossimImageData(0,
189  inputTile->getNumberOfBands());
191  theNormTile->setImageRectangle(reqRect);
195  ossim_float32* bands[3];
196  double averageI = 0.0;
197  double count = 0.0;
198  ossim_uint32 offset = 0;
199 
200  bands[0] = (ossim_float32*)theNormTile->getBuf();
202  {
203  bands[1] = (ossim_float32*)theNormTile->getBuf(1);
204  bands[2] = (ossim_float32*)theNormTile->getBuf(2);
205  }
206  else
207  {
208  bands[1] = bands[0];
209  bands[2] = bands[0];
210  }
211  ossimHsiVector hsi;
213  {
214  count = maxIdx;
215 
216  for(offset = 0; offset < maxIdx; ++offset)
217  {
218  hsi = ossimNormRgbVector(bands[0][offset], bands[1][offset], bands[2][offset]);
219 
220  averageI += hsi.getI();
221  }
222  }
223  else
224  {
225  for(offset = 0; offset < maxIdx; ++offset)
226  {
227  if((bands[0][offset] != 0.0)&&
228  (bands[1][offset] != 0.0)&&
229  (bands[2][offset] != 0.0))
230  {
231  hsi = ossimNormRgbVector(bands[0][offset], bands[1][offset], bands[2][offset]);
232  averageI += hsi.getI();
233 
234  ++count;
235  }
236  }
237  }
238  theInputBrightness = averageI / count;
240  }
241  else
242  {
243  theInputBrightness = .5;
244  }
245  }
246  theNormTile = 0;
247 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Will apply the algorithm: i*c + b where b is brightnes c is contrast i is the input value...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
T max(T a, T b)
Definition: ossimCommon.h:236
virtual ossim_uint32 getNumberOfBands() const
virtual void setImageRectangle(const ossimIrect &rect)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * find(const char *key) const
float ossim_float32
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
ossim_uint32 height() const
Definition: ossimIrect.h:487
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual ossim_uint32 getNumberOfDecimationLevels() const
Will return the number of resolution levels.
32 bit floating point
virtual void initialize()
Initialize the data buffer.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
ossimRefPtr< ossimBrightnessContrastSource > theBrightnessContrastSource
virtual void setNumericType(ossimNumericPropertyType type)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
ossimIpt midPoint() const
Definition: ossimIrect.h:750
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossim_float64 getI() const
double toDouble() const
virtual void copyTileToNormalizedBuffer(ossim_float64 *buf) const
Copies entire tile to buf passed in.
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 ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
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 bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossim_int32 y
Definition: ossimIpt.h:142
virtual const void * getBuf() const
ossimRefPtr< ossimImageData > theNormTile
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
ossim_int32 x
Definition: ossimIpt.h:141
virtual void setBrightness(ossim_float64 brightness)
void setCacheRefreshBit()
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
RTTI_DEF1(ossimBrightnessMatch, "ossimBrightnessMatch", ossimImageSourceFilter) ossimBrightnessMatch
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91