OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimBandMergeTool.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
8 #include <ossim/init/ossimInit.h>
11 #include <ossim/base/ossimNotify.h>
20 #include <iostream>
21 
22 using namespace std;
23 
25  "Merges multiple band files into a single RGB image.";
26 
27 static const std::string HISTO_STRETCH_KW = "histo_stretch";
28 
30 : m_stretchProduct(false)
31 {
32 }
33 
35 {
36 }
37 
39 {
40  // Add options.
42  ossimString usageString = ap.getApplicationName();
43  usageString += " bandmerge --red <red_band> --green <green_band> --blue <blue_band> [--stretch] <output-rgb-image>";
44  au->setCommandLineUsage(usageString);
45 
46  // Set the command line options:
48 
49  // Base class has its own:
51 
52  au->addCommandLineOption("--red", "<filename> Filename of red band. ");
53  au->addCommandLineOption("--green", "<filename> Filename of green band. ");
54  au->addCommandLineOption("--blue", "<filename> Filename of blue band. ");
55  au->addCommandLineOption("--stretch", "Optionally histogram-stretch the product image. ");
56 }
57 
59 {
61  return false;
62  if (m_helpRequested)
63  return true;
64 
65  ostringstream xmsg;
66 
67  std::string ts1;
69  int band_count = 0;
70 
71  if ( ap.read("--red", sp1))
72  {
73  ostringstream key;
75  m_kwl.addPair( key.str(), ts1 );
76  ++band_count;
77  }
78  if ( ap.read("--green", sp1))
79  {
80  ostringstream key;
82  m_kwl.addPair( key.str(), ts1 );
83  ++band_count;
84  }
85  if ( ap.read("--blue", sp1))
86  {
87  ostringstream key;
89  m_kwl.addPair( key.str(), ts1 );
90  ++band_count;
91  }
92  if (band_count != 3)
93  {
94  ossimNotify(ossimNotifyLevel_NOTICE)<<"ossimBandMergeUtil:"<<__LINE__
95  <<" Must supply three band filenames."<<endl;
96  return false;
97  }
98 
99  if ( ap.read("--stretch"))
100  {
101  m_kwl.addPair(HISTO_STRETCH_KW, string("true") );
102  }
103 
105  return true;
106 }
107 
109 {
110  kwl.getBoolKeywordValue(m_stretchProduct, HISTO_STRETCH_KW.c_str());
111 
112  m_kwl.add( ossimKeywordNames::PROJECTION_KW, "input", false );
114 }
115 
117 {
118  if (m_imgLayers.size() != 3)
119  {
120  ostringstream errMsg;
121  errMsg<<"ERROR ossimBandMergeUtil:"<<__LINE__<<" Expected 3 input layers but found "
122  <<m_imgLayers.size() <<". Cannot continue. "<<ends;
123  throw ossimException(errMsg.str());
124  }
125 
127  for (int band=0; band<3; band++)
128  {
129  ossimSingleImageChain* band_image = m_imgLayers[band].get();
130  bandList.push_back(band_image);
131 
132  // If performing histo stretch, try using existing histogram files before creating new ones:
133  if (m_stretchProduct)
134  initHistogramStretch(band_image);
135  }
137  m_procChain->add(combiner.get());
138 }
139 
141 {
142  ostringstream errMsg;
143 
144  // Check if this image already has a histogram file associated with it:
146  if (!handler.valid())
147  {
148  errMsg<<"ERROR ossimBandMergeUtil:"<<__LINE__<<" Bad handler returned for image chain.";
149  throw ossimException(errMsg.str());
150  }
151 
153  if (!histogram.valid())
154  {
155  errMsg<<"ERROR ossimBandMergeUtil:"<<__LINE__<<" Bad histogram returned from image handler.";
156  throw ossimException(errMsg.str());
157  }
158 
160  histogramRemapper->setEnableFlag(true);
162  histogramRemapper->setHistogram(histogram);
163  image->add(histogramRemapper.get());
164 }
165 
167 {
169 }
170 
172 {
174 
176  ossimString key = keybase + "0";
177  kwl.add(key.chars(), "<red-band>", true);
178  key = keybase + "1";
179  kwl.add(key.chars(), "<green-band>", true);
180  key = keybase + "2";
181  kwl.add(key.chars(), "<blue-band>", true);
182 
183  kwl.add(HISTO_STRETCH_KW.c_str(), "true|false", true);
184 }
185 
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
virtual void initProcessingChain()
Derived classes initialize their custom chains here.
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
static const char * PROJECTION_KW
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static const char * DESCRIPTION
Used by ossimUtilityFactory.
Represents serializable keyword/value map.
bool m_helpRequested
Definition: ossimTool.h:150
ossimRefPtr< const ossimImageHandler > getImageHandler() const
bool valid() const
Definition: ossimRefPtr.h:75
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
virtual void initHistogramStretch(ossimSingleImageChain *image)
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
void setCommandLineUsage(const ossimString &explanation)
virtual void getKwlTemplate(ossimKeywordlist &kwl)
Assigns a template keywordlist to string for initializing derived classes.
Definition: ossimTool.cpp:100
ossimApplicationUsage * getApplicationUsage()
ossimRefPtr< ossimMultiResLevelHistogram > getImageHistogram() const
Fetches the current entry image&#39;s histogram.
Single image chain class.
ossimRefPtr< ossimImageChain > m_procChain
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
void setStretchMode(StretchMode mode, bool rebuildTableFlag=false)
Sets remap mode to mode.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
void processRemainingArgs(ossimArgumentParser &ap)
Intended to be called after derived class has picked off its own options from the parser...
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
std::vector< ossimRefPtr< ossimSingleImageChain > > m_imgLayers
virtual void getKwlTemplate(ossimKeywordlist &kwl)
Assigns a template keywordlist to string for initializing derived classes.
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
bool getBoolKeywordValue(bool &rtn_val, const char *keyword, const char *prefix=0) const
[OLK, Aug/2008] Sets the boolean <rtn_val> depending on value associated with keyword for values = (y...
virtual void setEnableFlag(bool flag)
Definition: ossimSource.cpp:99
virtual bool execute()
Performs the actual product write.
void setDescription(const ossimString &desc)
static const char * IMAGE_FILE_KW
void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histogram)
Sets the histogram.
virtual bool execute()
Performs the actual product write.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)