OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimColorNormalizedFusion.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: Color normalized fusion
11 //
12 //*************************************************************************
13 // $Id: ossimColorNormalizedFusion.cpp 21631 2012-09-06 18:10:55Z dburken $
14 
19 
21  "ossimColorNormalizedFusion",
23 
26 {
27 }
28 
30  : ossimFusionCombiner(owner)
31 {
32 }
33 
35 {
36 }
37 
39  const ossimIrect& rect,
40  ossim_uint32 resLevel)
41 {
42  ossimRefPtr<ossimImageData> inputTile = getNormTile(rect, resLevel);
43 
44  if(!inputTile.valid())
45  {
46  return NULL;
47  }
49  {
50  return NULL;
51  }
52 
53  if((inputTile->getDataObjectStatus() == OSSIM_NULL)||
54  (inputTile->getDataObjectStatus() == OSSIM_EMPTY))
55  {
56  return NULL;
57  }
58 
59  if(theTile.valid())
60  {
62  }
63 
64 
65  ossim_float32* redBuff = (ossim_float32*)inputTile->getBuf(0);
66  ossim_float32* grnBuff = (ossim_float32*)inputTile->getBuf(1);
67  ossim_float32* bluBuff = (ossim_float32*)inputTile->getBuf(2);
68 
69  if(!redBuff||!grnBuff||!bluBuff)
70  {
71  return 0;
72  }
73  ossimRefPtr<ossimImageData> inputIntensity = getNormIntensity(rect, resLevel);
74 
75  if((!inputIntensity.valid()) ||
76  (!inputIntensity->getBuf()) ||
77  (inputIntensity->getDataObjectStatus() == OSSIM_EMPTY))
78  {
79  return 0;
80  }
81 
82  ossim_float32* mono_buff = (ossim_float32*)inputIntensity->getBuf(0);
83 
84  // Since NULL_PIX_VALUE is only used for Pix8 comparisons cast it now.
85  const float NULL_PIX_VALUE = (ossim_float32)inputIntensity->getNullPix(0);
86  const float MIN_PIX_VALUE = (ossim_float32)inputIntensity->getMinPix(0);
87  const float MAX_PIX_VALUE = (ossim_float32)inputIntensity->getMaxPix(0);
88 
89  float rgb_sum;
90  float r_wt; // Weight of red to rgb_sum.
91  float g_wt; // Weight of green to rgb_sum.
92  float b_wt; // Weight of blue to rgb_sum.
93  float iVal;
94  float redVal;
95  float greenVal;
96  float blueVal;
97 
99 
100  for (int i = 0; i < size; i++)
101  {
102  //***
103  // If no intensity source, or, no rgb source make output pixels null.
104  //***
105  if ( (mono_buff[i] == NULL_PIX_VALUE) ||
106  (redBuff[i] == NULL_PIX_VALUE &&
107  grnBuff[i] == NULL_PIX_VALUE &&
108  bluBuff[i] == NULL_PIX_VALUE) )
109 
110  {
111  redBuff[i] = NULL_PIX_VALUE;
112  grnBuff[i] = NULL_PIX_VALUE;
113  bluBuff[i] = NULL_PIX_VALUE;
114  }
115  else
116  {
117  redVal = redBuff[i];
118  greenVal = grnBuff[i];
119  blueVal = bluBuff[i];
120  rgb_sum = redVal + greenVal + blueVal + 3;
121  r_wt = 3 * (redVal + 1) / rgb_sum;
122  g_wt = 3 * (greenVal + 1) / rgb_sum;
123  b_wt = 3 * (blueVal + 1) / rgb_sum;
124  iVal = mono_buff[i] + 1;
125 
126  redVal = r_wt * iVal - 1;
127  greenVal = g_wt * iVal - 1;
128  blueVal = b_wt * iVal - 1;
129 
130  // Clip to max pixel value of radiometry.
131  if (redVal > MAX_PIX_VALUE) redVal = MAX_PIX_VALUE;
132  if (greenVal > MAX_PIX_VALUE) greenVal = MAX_PIX_VALUE;
133  if (blueVal > MAX_PIX_VALUE) blueVal = MAX_PIX_VALUE;
134 
135  // Assign chip value, clamp to min pixel value of radiometry if zero.
136  redBuff[i] = (float)(redVal>0.0 ? redVal : MIN_PIX_VALUE);
137  grnBuff[i] = (float)(greenVal>0.0 ? greenVal : MIN_PIX_VALUE);
138  bluBuff[i] = (float)(blueVal>0.0 ? blueVal : MIN_PIX_VALUE);
139  }
140  } // End of loop through pixels in chip.
141  theTile->copyNormalizedBufferToTile((float*)inputTile->getBuf());
142  theTile->validate();
143 
144  return theTile;
145 }
virtual ossim_uint32 getWidth() const
virtual const ossim_float64 * getMaxPix() const
virtual ossim_uint32 getNumberOfBands() const
ossimRefPtr< ossimImageData > getNormTile(const ossimIrect &rect, ossim_uint32 resLevel)
bool valid() const
Definition: ossimRefPtr.h:75
float ossim_float32
ossimRefPtr< ossimImageData > theTile
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
ossimImageSource * theInputConnection
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
yy_size_t size
virtual ossimDataObjectStatus validate() const
virtual void setImageRectangleAndBands(const ossimIrect &rect, ossim_uint32 numberOfBands)
ossimImageSource * theIntensityConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
virtual void copyNormalizedBufferToTile(ossim_float64 *buf)
Copies buf passed in to tile.
ossimRefPtr< ossimImageData > getNormIntensity(const ossimIrect &rect, ossim_uint32 resLevel)
virtual const ossim_float64 * getMinPix() const
virtual const void * getBuf() const
RTTI_DEF1(ossimColorNormalizedFusion, "ossimColorNormalizedFusion", ossimFusionCombiner)