33 static const string COLOR_CODING_KW =
"color_coding";
34 static const string SMOOTHING_KW =
"smoothing";
35 static const string THRESHOLD_KW =
"threshold";
36 static const string TMODE_KW =
"tmode";
37 static const string TOLERANCE_KW =
"tolerance";
38 static const string ALGORITHM_KW =
"algorithm";
39 static const ossimFilename DUMMY_OUTPUT_FILENAME =
"@@NEVER_USE_THIS@@";
40 static const ossimFilename TEMP_INDEX_FILENAME =
"temp_shoreline_index.tif";
41 static const ossimFilename TEMP_THRESHOLD_FILENAME =
"temp_shoreline_threshold.tif";
42 static const ossimFilename TEMP_MASK_FILENAME =
"temp_shoreline_mask.tif";
45 "Computes bitmap of water versus land areas in an input image.";
51 m_marginalValue (128),
57 m_thresholdMode(SIGMA),
75 usageString +=
" shoreline [options] [<output-vector-filename>]";
77 au->
setDescription(
"Computes vector shoreline from raster imagery. The vectors are output " 78 "in GeoJSON format. If an output filename is specified, the JSON is written to it. " 79 "Otherwise it is written to the console. The supported algorithms are (where A, B, etc are ordered input band files): \n" 80 " NDWI = (A - B) / (A + B) \n" 81 " AWEI = 4*(A + B) - 0.25*C - 2.75*D \n" 82 " PAN-THRESHOLD = A (no equation applied). The input single-band image is thresholded directly. \n");
86 "Specifies detection algorithm to apply. Supported names are: " 87 "\"ndwi\", \"aewi\", \"pan-threshold\"");
89 "Specifies the pixel values (0-255) for the output product corresponding to water, marginal, " 90 "and land zones. Defaults to 0, 128, and 255, respectively.");
92 "Outputs the raster, thresholded indexed image instead of a vector product. For engineering purposes.");
94 "Sensor used to compute Modified Normalized Difference Water Index. Currently only " 95 "\"ls8\" supported (default).");
97 "Applies gaussian filter to index raster file. The filter sigma must be specified (0.2 is good). Sigma=0 " 98 "indicates no smoothing.");
100 "Normalized threshold for converting the image to bitmap. Defaults to 0.55. If none specified, an optimized threshold" 103 "Mode to use for computing threshold from k-means statistics, where:\n" 104 " 0 = no auto-thresholding,\n" 105 " 1 = unweighted mean of means,\n" 106 " 2 = sigma-weighted mean of means (default),\n" 107 " 3 = variance-weighted mean of means." 108 "If \"--threshold\" option is specified, this option is ignored.\n");
110 "tolerance +- deviation from threshold for marginal classifications. Defaults to 0.01.");
127 if ( ap.
read(
"--algorithm", sp1))
130 if (ap.
read(
"--color-coding", sp1, sp2, sp3))
133 value<<ts1<<
" "<<ts2<<
" "<<ts3;
137 if ( ap.
read(
"--no-vector"))
140 if ( ap.
read(
"--sensor", sp1))
143 if ( ap.
read(
"--smooth", sp1))
146 if ( ap.
read(
"--threshold", sp1))
149 if ( ap.
read(
"--tmode", sp1))
152 if ( ap.
read(
"--tolerance", sp1))
157 while (ap.
read(
"--prop", sp1))
188 else if (value==
"awei")
190 else if (value==
"pan-threshold")
194 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Bad value encountered for keyword <" 195 <<ALGORITHM_KW<<
">.";
203 vector<ossimString> values = value.
split(
" ");
204 if (values.size() == 3)
212 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Unexpected number of values encountered for keyword <" 213 <<COLOR_CODING_KW<<
">.";
229 int tmode = value.
toInt();
230 if ((tmode >= 0) && (tmode <= 4))
276 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Encountered NaNs in AOI."<<ends;
286 equationSpec =
"in[0]/(in[0]+in[1])";
290 equationSpec =
"4*(in[0]+in[1]) - 0.25*in[2] - 2.75*in[3]";
301 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Expected "<< reqdNumInputs <<
" input images" 375 if (!potrace.
valid())
378 "ossim-potrace plugin to perform vectorization. Only the thresholded image is " 409 potrace_kwl.
add(
"mode",
"linestring");
410 potrace_kwl.
add(
"alphamax",
"1.0");
411 potrace_kwl.
add(
"turdsize",
"4");
417 #if OSSIM_HAS_JSONCPP 419 status = addPropsToJSON();
440 if (!indexImage.
valid())
442 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Error encountered reading index image at <" 463 remapper_kwl.
add(
"type",
"ossimBandLutFilter");
464 remapper_kwl.
add(
"enabled",
"1");
465 remapper_kwl.
add(
"mode",
"interpolated");
466 remapper_kwl.
add(
"scalar_type",
"U8");
467 remapper_kwl.
add(
"entry0.in",
"0.0");
468 remapper_kwl.
add(
"entry0.out", landValue.
chars());
469 remapper_kwl.
add(
"entry1.in", thresholdValueLo1.
chars());
470 remapper_kwl.
add(
"entry1.out", landValue.
chars());
473 remapper_kwl.
add(
"entry2.in", thresholdValueLo2.
chars());
474 remapper_kwl.
add(
"entry2.out", waterValue.
chars());
475 remapper_kwl.
add(
"entry3.in",
"1.0");
476 remapper_kwl.
add(
"entry3.out", waterValue.
chars());
480 remapper_kwl.
add(
"entry2.in", thresholdValueLo2.
chars());
481 remapper_kwl.
add(
"entry2.out", marginalValue.
chars());
482 remapper_kwl.
add(
"entry3.in", thresholdValueHi1.
chars());
483 remapper_kwl.
add(
"entry3.out", marginalValue.
chars());
484 remapper_kwl.
add(
"entry4.in", thresholdValueHi2.
chars());
485 remapper_kwl.
add(
"entry4.out", waterValue.
chars());
486 remapper_kwl.
add(
"entry5.in",
"1.0");
487 remapper_kwl.
add(
"entry5.out", waterValue.
chars());
497 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Error encountered creating threshold image at <" 513 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" No input handler in procession chain.";
517 if (!multi_histo.
valid())
519 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Could not establish an index histogram.";
524 if (!band_histo.
valid())
526 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" Null band histogram returned!";
537 xmsg<<
"ossimShorelineUtil:"<<__LINE__<<
" K-means clustering of histogram failed. Cannot " 538 "auto-compute threshold point.";
542 double mean0 = classifier->
getMean(0);
543 double mean1 = classifier->
getMean(1);
544 double sigma0 = classifier->
getSigma(0);
545 double sigma1 = classifier->
getSigma(1);
552 m_threshold = (sigma1*mean0 + sigma0*mean1)/(sigma0 + sigma1);
555 m_threshold = (sigma1*sigma1*mean0 + sigma0*sigma0*mean1)/(sigma0*sigma0 + sigma1*sigma1);
562 cout<<
"ossimShorelineUtil::autoComputeThreshold(): Using threshold = "<<
m_threshold<<endl;
565 #if OSSIM_HAS_JSONCPP 566 #include <json/json.h> 567 bool ossimShorelineTool::addPropsToJSON()
572 if (jsonFile.fail() || jsonFile.eof())
578 Json::Value properties(Json::objectValue);
588 properties[
"algorithm"] =
"NDWI";
591 properties[
"algorithm"] =
"AWEI";
594 properties[
"algorithm"] =
"UNKNOWN";
597 Json::Value fnames(Json::arrayValue);
600 Json::Value fname (
m_imgLayers[f]->getFilename().chars());
601 fnames.append(fname);
603 properties[
"input_files"] = fnames;
606 map<ossimString, ossimString>::iterator prop =
m_geoJsonProps.begin();
609 properties[prop->first.chars()] = prop->second.chars();
613 Json::Value& features = root[
"features"];
614 int n = features.size();
615 for (
int i=0; i<
n; ++i)
617 Json::Value& feature = features[i];
618 Json::Value& feature_props = feature[
"properties"];
619 feature_props = properties;
virtual void setOutputScalarType(ossimScalarType scalarType)
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
static const char * PROJECTION_KW
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Within the image chain will pass the head of the list.
ossimRefPtr< ossimHistogram > getHistogram(ossim_uint32 band, ossim_uint32 resLevel=0)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
static const char * OUTPUT_FILE_KW
virtual ossimImageSource * getFirstSource()
Return the first source which is the one that first receives the getTile request. ...
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
std::basic_ifstream< char > ifstream
Class for char input file streams.
const char * find(const char *key) const
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...
void setWindowSize(ossim_uint32 windowSize)
Size of resampling kernel width & height.
virtual void initialize()
Will combine the input data based on a supplied equation.
void addList(const ossimKeywordlist &src, bool overwrite=true)
static ossimString toString(bool aValue)
Numeric to string methods.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
void setImageSize(const ossimIpt &size)
virtual void setEquation(const ossimString &equ)
ossimRefPtr< ossimMultiResLevelHistogram > getImageHistogram() const
Fetches the current entry image's histogram.
void setSamples(T *samples, ossim_uint32 num_entries)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
static const char * SENSOR_ID_KW
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
class for symmetric Gaussian filtering implemented as two separable horizontal/vertical gaussian filt...
os2<< "> n<< " > nendobj n
void setNumClusters(ossim_uint32 K)
unsigned int ossim_uint32
const char * chars() const
For backward compatibility.
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
void setGaussStd(const ossim_float64 &v)
64 bit normalized floating point
This class defines an abstract Handler which all image handlers(loaders) should derive from...
void setDescription(const ossimString &desc)
ossimFilename fileNoExtension() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
static ossimImageHandlerRegistry * instance()
std::basic_ofstream< char > ofstream
Class for char output file streams.
void setPopulations(T *populations, ossim_uint32 num_entries)
double getSigma(ossim_uint32 groupId) const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
double getMean(ossim_uint32 groupId) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)