OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimIntensityAdjustmentFilter.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: ossimIntensityAdjustmentFilter.cpp 13330 2008-07-28 18:04:40Z dburken $
14 #include <ossim/base/ossimDrect.h>
17 
18 RTTI_DEF1(ossimIntensityAdjustmentFilter, "ossimIntensityAdjustmentFilter", ossimImageSourceFilter);
19 
22  theMeanIntensityTarget(ossim::nan()),
23  theNormTile(NULL),
24  theTile(NULL),
25  theBlankTile(NULL)
26 {
28 }
29 
31 {
32 }
33 
35  const ossimIrect& rect,
36  ossim_uint32 resLevel)
37 {
38  if (!theTile.valid())
39  {
40  allocate(); // first time through.
41  }
42 
43  if(theBlankTile.valid())
44  {
46  }
48  {
49  return theBlankTile;
50  }
52  theInputConnection->getTile(rect, resLevel);
53 
54  if(!isSourceEnabled())
55  {
56  return data;
57  }
60  loadNormTile(data);
61 
63  {
65  }
66 
67  loadNormTile(data);
68 
71  {
72  float* buf[3];
73  if(data->getNumberOfBands() == 3)
74  {
75  buf[0] = (float*)theNormTile->getBuf(0);
76  buf[1] = (float*)theNormTile->getBuf(1);
77  buf[2] = (float*)theNormTile->getBuf(2);
78  }
79  else
80  {
81  buf[0] = (float*)theNormTile->getBuf(0);
82  buf[1] = (float*)theNormTile->getBuf(0);
83  buf[2] = (float*)theNormTile->getBuf(0);
84 
85  }
86  ossim_int32 y = 0;
87  ossim_int32 x = 0;
88  ossim_int32 upperY = theNormTile->getHeight();
89  ossim_int32 upperX = theNormTile->getWidth();
90  ossimIpt origin = rect.ul();
91 
92  for(y = 0; y < upperY; ++y)
93  {
94  for(x = 0; x < upperX; ++x)
95  {
96  ossimIpt pt = ossimIpt(origin.x + x,
97  origin.y + y) - theGridBounds.ul();
98 
99  if((buf[0] != 0) &&
100  (buf[1] != 0) &&
101  (buf[2] != 0))
102  {
103 
104  ossimRgbVector rgb((ossim_uint8)(*(buf[0])*255.0),
105  (ossim_uint8)(*(buf[1])*255.0),
106  (ossim_uint8)(*(buf[2])*255.0));
107  ossimHsvVector hsv(rgb);
108 
109  hsv.setV(matchTargetMean(hsv.getV(),
110  theMeanIntensityGrid(pt.x, pt.y),
113  theNormTile->getMaxPix(0)));
114  ossimRgbVector result(hsv);
115 
116  *buf[0] = result.getR()/255.0;
117  *buf[1] = result.getG()/255.0;
118  *buf[2] = result.getB()/255.0;
119  }
120 
121  ++buf[0];
122  ++buf[1];
123  ++buf[2];
124  }
125  }
126  }
128  theTile->validate();
129 
130  return theTile;
131 }
132 
134 {
136 
137  theNormTile = NULL;
138  theBlankTile = NULL;
139 
141  {
143  }
144  else
145  {
147  }
148 }
149 
151 {
154  theTile->initialize();
155 }
156 
158  double targetMean)
159 {
161  {
162  ossim_uint32 x = 0;
163  ossim_uint32 y = 0;
164 
166 
167  ossimDrect rect(0,
168  0,
169  theGridBounds.width()-1,
170  theGridBounds.height()-1);
171 
173  ossimDpt(spacing),
174  0);
175 
176  for(y = 0; y <= theGridBounds.height(); y+=spacing.y)
177  {
178  for(x = 0; x <= theGridBounds.width(); x+=spacing.x)
179  {
180  ossimIpt ul(x - 16,
181  y - 16);
182 
183  ossimIrect sampleRect(ul.x,
184  ul.y,
185  ul.x + 31,
186  ul.y + 31);
188  double mean = computeMeanIntensity(data);
190  }
191  }
192 // theMeanIntensityGrid.interpolateNullValuedNodes();
193  }
194  theMeanIntensityTarget = targetMean;
195 }
196 
199 {
200  double result = 0;
201  double divisor = 0;
202 
203  if(data.valid() &&
204  (data->getDataObjectStatus()!=OSSIM_NULL)&&
205  (data->getDataObjectStatus()!=OSSIM_EMPTY))
206  {
207  loadNormTile(data);
208 
209  int i = 0;
210  int upper = data->getWidth()*data->getHeight();
211  float* buf[3];
212  if(data->getNumberOfBands() == 3)
213  {
214  buf[0] = (float*)theNormTile->getBuf(0);
215  buf[1] = (float*)theNormTile->getBuf(1);
216  buf[2] = (float*)theNormTile->getBuf(2);
217  }
218  else
219  {
220  buf[0] = (float*)theNormTile->getBuf();
221  buf[1] = (float*)theNormTile->getBuf();
222  buf[2] = (float*)theNormTile->getBuf();
223  }
224  for(i = 0; i < upper; ++i)
225  {
226  ossimRgbVector rgb((ossim_uint8)(*(buf[0])*255.0),
227  (ossim_uint8)(*(buf[1])*255.0),
228  (ossim_uint8)(*(buf[2])*255.0));
229  ossimHsvVector hsv(rgb);
230  if(hsv.getV() > 0.0)
231  {
232  result += hsv.getV();
233  divisor += 1.0;
234  }
235  ++buf[0];
236  ++buf[1];
237  ++buf[2];
238  }
239  }
240 
241  if(divisor > 0.0)
242  {
243  result /= divisor;
244  }
245  return result;
246 }
247 
249 {
250  if(!theNormTile)
251  {
254  data->getNumberOfBands(),
255  data->getWidth(),
256  data->getHeight());
258  }
259  else
260  {
262  }
265 }
266 
268  double meanValue,
269  double targetMean,
270  double minValue,
271  double maxValue)
272 {
273  // max change
274  const double delta = targetMean - meanValue;
275  double weight=0.0;
276 
277  // weight max change dependend on proximity to end points
278  if (inputValue <= meanValue)
279  {
280  weight = fabs((inputValue - minValue) / (meanValue - minValue));
281  }
282  else
283  {
284  weight = fabs((maxValue - inputValue) / (maxValue - meanValue));
285  }
286 
287  return (inputValue + (delta * weight));
288 }
virtual ossim_uint32 getWidth() const
ossim_uint32 x
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 const ossim_float64 * getMaxPix() const
ossimRefPtr< ossimImageData > theBlankTile
virtual ossim_uint32 getNumberOfBands() const
unsigned char getR() const
ossimRefPtr< ossimImageData > theNormTile
void createAndPopulateGrid(const ossimIpt &spacing, double targetMean=.5)
virtual void setImageRectangle(const ossimIrect &rect)
double matchTargetMean(double inputValue, double meanValue, double targetMean, double minValue, double maxValue)
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual void initialize()
Initialize the data buffer.
virtual ossimObject * dup() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
virtual ossimIrect getImageRectangle() const
unsigned char getB() const
void setNearestNode(const ossimDpt &uv_point, const double &value)
virtual void copyTileToNormalizedBuffer(ossim_float64 *buf) const
Copies entire tile to buf passed in.
virtual void copyNormalizedBufferToTile(ossim_float64 *buf)
Copies buf passed in to tile.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
RTTI_DEF1(ossimIntensityAdjustmentFilter, "ossimIntensityAdjustmentFilter", ossimImageSourceFilter)
virtual const ossim_float64 * getMinPix() const
unsigned char getG() const
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
virtual const void * getBuf() const
void loadNormTile(ossimRefPtr< ossimImageData > &data)
void setV(float V)
ossim_int32 x
Definition: ossimIpt.h:141
float getV() const
double computeMeanIntensity(ossimRefPtr< ossimImageData > &data)
unsigned char ossim_uint8
double meanValue()
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91