[pktools] 58/375: added active learning functionality in pkclassify_svm.cc
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:53:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastic-guest pushed a commit to branch upstream-master
in repository pktools.
commit ea38ebffca1c3fadd5344901f5379517a8b80708
Author: user <user at osgeolive.(none)>
Date: Wed Feb 13 07:50:21 2013 +0100
added active learning functionality in pkclassify_svm.cc
---
INSTALL | 5 +-
README | 5 +-
doc/createappsdox.sh | 2 +-
doc/mainpage.dox | 69 ++++++++++++++++-----
src/algorithms/FeatureSelector.h | 10 +--
src/apps/pkclassify_svm.cc | 112 +++++++++++++++++++++++++++++++---
src/apps/pkeditogr.cc | 61 +++++++++++++-----
src/apps/pkegcs.cc | 4 +-
src/apps/pkfs_svm.cc | 2 +-
src/apps/pklas2img.cc | 36 +++++------
src/apps/pkndvi.cc | 2 +-
src/apps/pkopt_svm.cc | 2 +-
src/base/{PosValue.h => IndexValue.h} | 22 +++----
src/base/PosValue.h | 3 +-
src/base/Vector2d.h | 8 +--
src/imageclasses/ImgWriterOgr.cc | 8 +++
src/imageclasses/ImgWriterOgr.h | 1 +
17 files changed, 264 insertions(+), 88 deletions(-)
diff --git a/INSTALL b/INSTALL
index db6c84a..d564d13 100644
--- a/INSTALL
+++ b/INSTALL
@@ -12,8 +12,9 @@ The simplest way to compile this package is:
configure options (use ./configure --help for help info)
--with-gdal=<path to gdal-config file>
- --enable-fann (to include pkclassify_nn when FANN is installed)
- --enable-las (to include pklas2img when LIBLAS >= 1.6 is installed)
+ --enable-fann
+ --enable-las
+ --enable-nlopt
2. Type `make' to compile the package.
diff --git a/README b/README
index aa8b4ca..e92bbc6 100644
--- a/README
+++ b/README
@@ -14,7 +14,4 @@ To install the programs in pktools, refer to the file INSTALL
Change history
-------------
-version 1.0 June 25 2012, first public release of the code
-version 2.1 September 04 2012, introduced --enable-fann and --enable-las in configuration
-version 2.2 September 13 2012, support spectral filtering (z-dimension) in pkfilter using tapz option
-version 2.3 October 20 2012, support for SVM classifier
+see Changelog
diff --git a/doc/createappsdox.sh b/doc/createappsdox.sh
index 57a7f64..fb69da6 100755
--- a/doc/createappsdox.sh
+++ b/doc/createappsdox.sh
@@ -15,7 +15,7 @@ thelongdescription
## OPTIONS ##
- use either \`-short\` or \`--long\` options (both \`--long=value\` and \`--long value\` are supported)
- - short option \`-h\` shows basic options only, long option \`--h\` shows all options
+ - short option \`-h\` shows basic options only, long option \`--help\` shows all options
|short|long|type|default|description|
|-----|----|----|-------|-----------|
EOF
diff --git a/doc/mainpage.dox b/doc/mainpage.dox
index 995473b..7f8728b 100644
--- a/doc/mainpage.dox
+++ b/doc/mainpage.dox
@@ -1,22 +1,32 @@
\mainpage
-Introduction
-============
-pktools is a collection of programs written by Pieter Kempeneers in C++ to perform operations on raster images.
-It heavily relies on the Geospatial Data Abstraction Library (GDAL, http://www.gdal.org) and OGR. Some of the programs are similar to the gdal tools (gdalinfo, gdal_translate, gdal_merge,...) and many of the functionalities provided in pktools already exist. The reason for implementing pktools is a combination of personal preference and additional functionality.
+
+ - \ref pktools_introduction "Introduction"
+ - \ref pktools_license "License"
+ - \ref pktools_download "Download"
+ - \ref pktools_refer "How to refer"
+ - \ref pktools_installation "Installation"
+ - \ref available_tools "Available Tools"
+
+\section pktools_introduction Introduction
+
+pktools is a collection of programs written in C++ to perform operations, mostly on raster images.
+It heavily relies on the Geospatial Data Abstraction Library (GDAL, http://www.gdal.org) and OGR. The programs are similar to the gdal tools (gdalinfo, gdal_translate, gdal_merge,...) and some of the functionalities provided in pktools already exist in the gdal tools. The reason for implementing pktools is a combination of personal preference and additional functionality.
All utilities in pktools use command line options and have a built in help
- use the `-h` option to get help
- pktools ALWAYS use -i for input and -o for output (unlike GDAL utilities that commonly use last argument as output and second but last argument as input)
-License
-=======
-pktools is released under the GNU General Public License version3
+Currently the tools only work in a Linux environment
+
+\section pktools_license License
+
+pktools is written by Pieter Kempeneers and released under the GNU General Public License version3
See http://www.gnu.org/licenses for more details
-Download
-========
+\section pktools_download Download
+
You can download the latest release
- from http://download.savannah.gnu.org/releases/pktools/ (tar ball)
- or by getting a copy of the Git repository
@@ -25,10 +35,41 @@ You can download the latest release
git clone git://git.savannah.nongnu.org/pktools.git
~~~
-How to refer
-============
+\section pktools_refer How to refer
+
You are welcome to refer to pktools as: http://pktools.nongnu.org (Pieter Kempeneers)
-List of pktools
-===============
-\ref available_tools "Available Tools"
\ No newline at end of file
+contact: kempenep at gmail.com
+
+\section pktools_installation Installation
+Download the latest release from http://download.savannah.gnu.org/releases/pktools/ (e.g., pktools-2.3.tar.gz)
+\code
+tar xzvf pktools-2.3.tar.gz
+cd pktools-2.3
+\endcode
+Basic installation (please refer to INSTALL file for more advanced configuration)
+\code
+./configure
+make
+sudo make install
+\endcode
+
+Prerequisites (required)
+------------------------
+packages to install before pktool
+ - libgdal-dev http://trac.osgeo.org/gdal/wiki/BuildingOnUnix (or via repository)
+ - libgsl0-dev http://www.gnu.org/software/gsl/ (or via repository)
+
+Prerequisites (optional)
+------------------------
+if configured with `--enable-nlopt`: required for \ref pkfs_nn, \ref pkfs_svm, \ref pkopt_svm
+ - nlopt http://ab-initio.mit.edu/wiki/index.php/NLopt#Download_and_installation
+
+if configured with `--enable-las`: required for \ref pklas2img
+ - cmake (2.8.1+) http://www.cmake.org/ (or via repository)
+ - libboost-dev (1.38.0+) http://www.boost.org/ (or via repository)
+ - liblas http://www.liblas.org/compilation.html#compilation
+ (notice this is not the same package as laslib...)
+
+if configured with `--enable-fann`: required for \ref pkclassify_nn, \ref pkfs_nn, \ref pkfs_nn
+ - libfann-dev http://leenissen.dk/fann/wp/download/ (or via repository)
diff --git a/src/algorithms/FeatureSelector.h b/src/algorithms/FeatureSelector.h
index 6eebf46..fcd3f15 100644
--- a/src/algorithms/FeatureSelector.h
+++ b/src/algorithms/FeatureSelector.h
@@ -27,7 +27,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <algorithm>
#include <iostream>
#include <iomanip>
-#include "PosValue.h"
+#include "IndexValue.h"
#include "Vector2d.h"
#include "gsl/gsl_combination.h"
@@ -57,7 +57,7 @@ template<class T> double FeatureSelector::forwardUnivariate(vector< Vector2d<T>
int k=subset.size();
if(k>=maxFeatures)
return -1;
- vector<PosValue> cost(maxLevels);
+ vector<IndexValue> cost(maxLevels);
list<int> tmpset=subset;//temporary set of selected features (levels)
vector< Vector2d<T> > tmp(v.size());
for(int ilevel=0;ilevel<maxLevels;++ilevel){
@@ -68,13 +68,13 @@ template<class T> double FeatureSelector::forwardUnivariate(vector< Vector2d<T>
v[iclass].selectCols(tmpset,tmp[iclass]);
}
try{
- PosValue pv;
+ IndexValue pv;
pv.position=ilevel;
pv.value=getCost(tmp);
cost[ilevel]=pv;
}
catch(...){
- PosValue pv;
+ IndexValue pv;
pv.position=ilevel;
pv.value=-1;
cost[ilevel]=pv;
@@ -82,7 +82,7 @@ template<class T> double FeatureSelector::forwardUnivariate(vector< Vector2d<T>
tmpset.pop_back();
}
}
- sort(cost.begin(),cost.end(),Compare_PosValue());//decreasing order
+ sort(cost.begin(),cost.end(),Compare_IndexValue());//decreasing order
int ilevel=0;
while((subset.size()<maxFeatures)&&(ilevel<maxLevels)){
if(cost[ilevel].value>0)
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 61fb41e..1cd03c8 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -25,6 +25,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderOgr.h"
#include "imageclasses/ImgWriterOgr.h"
#include "base/Optionpk.h"
+#include "base/PosValue.h"
#include "algorithms/ConfusionMatrix.h"
#include "algorithms/svm.h"
#include "pkclassify_nn.h"
@@ -96,11 +97,11 @@ int main(int argc, char *argv[])
Optionpk<short> band_opt("b", "band", "band index (starting from 0, either use band option or use start to end)");
Optionpk<double> offset_opt("\0", "offset", "offset value for each spectral band input features: refl[band]=(DN[band]-offset[band])/scale[band]", 0.0);
Optionpk<double> scale_opt("\0", "scale", "scale value for each spectral band input features: refl=(DN[band]-offset[band])/scale[band] (use 0 if scale min and max in each band to -1.0 and 1.0)", 0.0);
- Optionpk<unsigned short> aggreg_opt("a", "aggreg", "how to combine aggregated classifiers, see also rc option (0: no aggregation, 1: sum rule, 2: max rule).",0);
+ Optionpk<unsigned short> aggreg_opt("a", "aggreg", "how to combine aggregated classifiers, see also rc option (0: no aggregation, 1: sum rule, 2: max rule).",1);
Optionpk<double> priors_opt("p", "prior", "prior probabilities for each class (e.g., -p 0.3 -p 0.3 -p 0.2 )", 0.0);
Optionpk<unsigned short> cv_opt("cv", "cv", "n-fold cross validation mode",0);
Optionpk<unsigned short> svm_type_opt("svmt", "svmtype", "type of SVM (0: C-SVC, 1: nu-SVC, 2: one-class SVM, 3: epsilon-SVR, 4: nu-SVR)",0);
- Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*|u-v|^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
+ Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*(u-v)^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
Optionpk<unsigned short> kernel_degree_opt("kd", "kd", "degree in kernel function",3);
Optionpk<float> gamma_opt("g", "gamma", "gamma in kernel function",0);
Optionpk<float> coef0_opt("c0", "coef0", "coef0 in kernel function",0);
@@ -124,6 +125,8 @@ int main(int argc, char *argv[])
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]");
Optionpk<string> colorTable_opt("ct", "ct", "colour table in ascii format having 5 columns: id R G B ALFA (0: transparent, 255: solid)");
Optionpk<string> prob_opt("\0", "prob", "probability image.");
+ Optionpk<string> active_opt("active", "active", "ogr output for active training sample.");
+ Optionpk<unsigned int> nactive_opt("na", "nactive", "number of active training points",1);
Optionpk<short> verbose_opt("v", "verbose", "set to: 0 (results only), 1 (confusion matrix), 2 (debug)",0);
bool doProcess;//stop process when program was invoked with help option (-h --help)
@@ -166,6 +169,8 @@ int main(int argc, char *argv[])
colorTable_opt.retrieveOption(argc,argv);
option_opt.retrieveOption(argc,argv);
prob_opt.retrieveOption(argc,argv);
+ active_opt.retrieveOption(argc,argv);
+ nactive_opt.retrieveOption(argc,argv);
verbose_opt.retrieveOption(argc,argv);
}
catch(string predefinedString){
@@ -194,9 +199,23 @@ int main(int argc, char *argv[])
unsigned short nbag=(training_opt.size()>1)?training_opt.size():bag_opt[0];
if(verbose_opt[0]>=1)
std::cout << "number of bootstrap aggregations: " << nbag << std::endl;
-
+
+ ImgWriterOgr activeWriter;
+ if(active_opt.size()){
+ ImgReaderOgr trainingReader(training_opt[0]);
+ activeWriter.open(active_opt[0]);
+ activeWriter.createLayer(active_opt[0],trainingReader.getProjection(),wkbPoint,NULL);
+ activeWriter.copyFields(trainingReader);
+ }
+ vector<PosValue> activePoints(nactive_opt[0]);
+ for(int iactive=0;iactive<activePoints.size();++iactive){
+ activePoints[iactive].value=1.0;
+ activePoints[iactive].posx=0.0;
+ activePoints[iactive].posy=0.0;
+ }
unsigned int totalSamples=0;
+ unsigned int nactive=0;
vector<short> vcode;//unique reclass codes (e.g., -rc 1 -rc 1 -rc 2 -rc 2 -> vcode[0]=1,vcode[1]=2)
vector<struct svm_model*> svm(nbag);
vector<struct svm_parameter> param(nbag);
@@ -675,6 +694,7 @@ int main(int argc, char *argv[])
ImgWriterGdal classImageBag;
ImgWriterGdal classImageOut;
ImgWriterGdal probImage;
+
string imageType=testImage.getImageType();
if(oformat_opt.size())//default
imageType=oformat_opt[0];
@@ -714,6 +734,11 @@ int main(int argc, char *argv[])
if(classBag_opt.size())
classBag.resize(nbag,ncol);
//read all bands of all pixels in this line in hline
+ // for(int iband=0;iband<testImage.nrOfBand();++iband){
+ // testImage.readData(buffer,GDT_Float32,iline,iband);
+ // for(int icol=0;icol<ncol;++icol)
+ // hpixel[icol].push_back(buffer[icol]);
+ // }
try{
if(band_opt.size()){
for(int iband=0;iband<band_opt.size();++iband){
@@ -798,7 +823,27 @@ int main(int argc, char *argv[])
}
}
bool valid=false;
- for(int iband=0;iband<nband;++iband){
+ // if(band_opt.size()){
+ // for(int iband=0;iband<band_opt.size();++iband){
+ // assert(band_opt[iband]>0);
+ // assert(band_opt[iband]<hpixel[icol].size());
+ // if(hpixel[icol][band_opt[iband]]){
+ // valid=true;
+ // break;
+ // }
+ // }
+ // }
+ // else{
+ // for(int iband=start_opt[0];iband<start_opt[0]+nband;++iband){
+ // assert(iband>0);
+ // assert(iband<hpixel[icol].size());
+ // if(hpixel[icol][iband]){
+ // valid=true;
+ // break;
+ // }
+ // }
+ // }
+ for(int iband=0;iband<hpixel[icol].size();++iband){
if(hpixel[icol][iband]){
valid=true;
break;
@@ -825,6 +870,18 @@ int main(int argc, char *argv[])
// x = (struct svm_node *) malloc((fpixel[icol].size()+1)*sizeof(struct svm_node));
x = (struct svm_node *) malloc((nband+1)*sizeof(struct svm_node));
// for(int i=0;i<fpixel[icol].size();++i){
+ // if(band_opt.size()){
+ // for(int iband=0;iband<band_opt.size();++iband){
+ // x[iband].index=iband+1;
+ // x[iband].value=(hpixel[icol][band_opt[iband]]-offset[ibag][iband])/scale[ibag][iband];
+ // }
+ // }
+ // else{
+ // for(int iband=start_opt[0];iband<start_opt[0]+nband;++iband){
+ // x[iband].index=iband+1;
+ // x[iband].value=(hpixel[icol][iband]-offset[ibag][iband])/scale[ibag][iband];
+ // }
+ // }
for(int iband=0;iband<nband;++iband){
x[iband].index=iband+1;
// x[i].value=fpixel[icol][i];
@@ -884,15 +941,29 @@ int main(int argc, char *argv[])
}//ibag
//search for max class prob
- float maxBag=0;
+ float maxBag1=0;//max probability
+ float maxBag2=0;//second max probability
float normBag=0;
for(short iclass=0;iclass<nreclass;++iclass){
- if(prOut[iclass][icol]>maxBag){
- maxBag=prOut[iclass][icol];
+ if(prOut[iclass][icol]>maxBag1){
+ maxBag1=prOut[iclass][icol];
classOut[icol]=vcode[iclass];
}
+ else if(prOut[iclass][icol]>maxBag2)
+ maxBag2=prOut[iclass][icol];
normBag+=prOut[iclass][icol];
}
+ float maxDiff=maxBag1-maxBag2;
+ if(active_opt.size()&&maxDiff){
+ if(maxDiff<activePoints.back().value){
+ activePoints.back().value=maxDiff;//replace largest value (last)
+ activePoints.back().posx=icol;
+ activePoints.back().posy=iline;
+ std::sort(activePoints.begin(),activePoints.end(),Increase_PosValue());//sort in ascending order (smallest first, largest last)
+ if(verbose_opt[0])
+ std::cout << activePoints.back().posx << " " << activePoints.back().posy << " " << activePoints.back().value << std::endl;
+ }
+ }
//normalize prOut and convert to percentage
if(prob_opt.size()){
for(short iclass=0;iclass<nreclass;++iclass){
@@ -917,6 +988,28 @@ int main(int argc, char *argv[])
pfnProgress(progress,pszMessage,pProgressArg);
}
}
+ //write active learning points
+ if(active_opt.size()){
+ for(int iactive=0;iactive<activePoints.size();++iactive){
+ std::map<string,double> pointMap;
+ for(int iband=0;iband<testImage.nrOfBand();++iband){
+ double value;
+ testImage.readData(value,GDT_Float64,static_cast<int>(activePoints[iactive].posx),static_cast<int>(activePoints[iactive].posy),iband);
+ ostringstream fs;
+ fs << "B" << iband;
+ pointMap[fs.str()]=value;
+ }
+ pointMap[label_opt[0]]=0;
+ double x, y;
+ testImage.image2geo(activePoints[iactive].posx,activePoints[iactive].posy,x,y);
+ std::string fieldname="id";//number of the point
+ //test
+ // pointMap["col"]=activePoints[iactive].posx;
+ // pointMap["row"]=activePoints[iactive].posy;
+ activeWriter.addPoint(x,y,pointMap,fieldname,++nactive);
+ }
+ }
+
testImage.close();
if(prob_opt.size())
probImage.close();
@@ -1078,9 +1171,12 @@ int main(int argc, char *argv[])
imgWriterOgr.close();
}
}
+ if(active_opt.size())
+ activeWriter.close();
for(int ibag=0;ibag<nbag;++ibag){
- svm_destroy_param[ibag](¶m[ibag]);
+ // svm_destroy_param[ibag](¶m[ibag]);
+ svm_destroy_param(¶m[ibag]);
free(prob[ibag].y);
free(prob[ibag].x);
free(x_space[ibag]);
diff --git a/src/apps/pkeditogr.cc b/src/apps/pkeditogr.cc
index 531c0d6..09db8d8 100644
--- a/src/apps/pkeditogr.cc
+++ b/src/apps/pkeditogr.cc
@@ -30,9 +30,12 @@ int main(int argc, char *argv[])
Optionpk<string> input_opt("i", "input", "Input image");
Optionpk<string> output_opt("o", "output", "Output mask file");
Optionpk<string> field_opt("f", "field", "output field names (number must exactly match input fields)");
+ Optionpk<long int> setfeature_opt("sf", "sf", "id of feature(s) to set (start from 0)");
+ Optionpk<string> setname_opt("sn", "sn", "name(s) of field(s) to set");
+ Optionpk<string> setvalue_opt("sv", "sv", "value(s) of field(s) to set");
Optionpk<string> addname_opt("an", "an", "name(s) of field(s) to add (number must exactly match field types)");
Optionpk<string> addtype_opt("at", "at", "type(s) of field(s) to add (number must exactly match fieldnames to add", "Real");
- Optionpk<string> default_opt("d", "default", "default value(s) for new field(s)");
+ Optionpk<string> addvalue_opt("av", "av", "value(s) of field(s) to add");
Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
bool doProcess;//stop process when program was invoked with help option (-h --help)
@@ -42,7 +45,10 @@ int main(int argc, char *argv[])
field_opt.retrieveOption(argc,argv);
addname_opt.retrieveOption(argc,argv);
addtype_opt.retrieveOption(argc,argv);
- default_opt.retrieveOption(argc,argv);
+ addvalue_opt.retrieveOption(argc,argv);
+ setfeature_opt.retrieveOption(argc,argv);
+ setname_opt.retrieveOption(argc,argv);
+ setvalue_opt.retrieveOption(argc,argv);
verbose_opt.retrieveOption(argc,argv);
}
catch(string predefinedString){
@@ -113,8 +119,8 @@ int main(int argc, char *argv[])
std::cout << "add " << addname_opt.size() << " fields" << std::endl;
if(addname_opt.size()){
assert(addname_opt.size()==addtype_opt.size());
- while(default_opt.size()<addname_opt.size())
- default_opt.push_back(default_opt.back());
+ while(addvalue_opt.size()<addname_opt.size())
+ addvalue_opt.push_back(addvalue_opt.back());
}
for(int iname=0;iname<addname_opt.size();++iname){
if(verbose_opt[0])
@@ -126,12 +132,8 @@ int main(int argc, char *argv[])
std::cout << addname_opt.size() << " fields created" << std::endl;
}
OGRFeature *poFeature;
- // while(true){// (poFeature = imgReaderOgr.getLayer()->GetNextFeature()) != NULL ){
while((poFeature = ogrReader.getLayer()->GetNextFeature()) != NULL ){
++ifeature;
- // poFeature = ogrReader.getLayer()->GetNextFeature();
- // if( poFeature == NULL )
- // break;
OGRFeature *poDstFeature = NULL;
poDstFeature=ogrWriter.createFeature();
if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ){
@@ -144,7 +146,34 @@ int main(int argc, char *argv[])
OGRFeature::DestroyFeature( poFeature );
OGRFeature::DestroyFeature( poDstFeature );
}
+ long int fid=poFeature->GetFID();
+ //test
+ std::cout << "fid: " << fid << std::endl;
poDstFeature->SetFID( poFeature->GetFID() );
+ for(int ifeature=0;ifeature<setfeature_opt.size();++ifeature){
+ //test
+ std::cout << "set feature " << setfeature_opt[ifeature] << std::endl;
+ if(fid==setfeature_opt[ifeature]){
+ switch(poDstFeature->GetFieldDefnRef(fid)->GetType()){
+ case(OFTReal):
+ poDstFeature->SetField(setname_opt[ifeature].c_str(),string2type<float>(setvalue_opt[ifeature]));
+ break;
+ case(OFTInteger):
+ //test
+ std::cout << "set field " << setname_opt[ifeature] << " to " << setvalue_opt[ifeature] << std::endl;
+ poDstFeature->SetField(setname_opt[ifeature].c_str(),string2type<int>(setvalue_opt[ifeature]));
+ break;
+ case(OFTString):
+ poDstFeature->SetField(setname_opt[ifeature].c_str(),setvalue_opt[ifeature].c_str());
+ break;
+ default:
+ std::cerr << "Error: field type not supported" << std::endl;
+ exit(1);
+ break;
+ }
+ }
+ }
+
//set default values for new fields
if(verbose_opt[0])
std::cout << "set default values for new fields in feature " << ifeature << std::endl;
@@ -152,23 +181,24 @@ int main(int argc, char *argv[])
switch(fieldType[iname]){
case(OFTReal):
if(verbose_opt[0])
- std::cout << "set field " << addname_opt[iname] << " to default " << string2type<float>(default_opt[iname]) << std::endl;
- poDstFeature->SetField(addname_opt[iname].c_str(),string2type<float>(default_opt[iname]));
+ std::cout << "set field " << addname_opt[iname] << " to default " << string2type<float>(addvalue_opt[iname]) << std::endl;
+ poDstFeature->SetField(addname_opt[iname].c_str(),string2type<float>(addvalue_opt[iname]));
break;
case(OFTInteger):
if(verbose_opt[0])
- std::cout << "set field " << addname_opt[iname] << " to default " << string2type<int>(default_opt[iname]) << std::endl;
- poDstFeature->SetField(addname_opt[iname].c_str(),string2type<int>(default_opt[iname]));
+ std::cout << "set field " << addname_opt[iname] << " to default " << string2type<int>(addvalue_opt[iname]) << std::endl;
+ poDstFeature->SetField(addname_opt[iname].c_str(),string2type<int>(addvalue_opt[iname]));
break;
case(OFTString):
if(verbose_opt[0])
- std::cout << "set field " << addname_opt[iname] << " to default " << default_opt[iname] << std::endl;
- poDstFeature->SetField(addname_opt[iname].c_str(),default_opt[iname].c_str());
+ std::cout << "set field " << addname_opt[iname] << " to default " << addvalue_opt[iname] << std::endl;
+ poDstFeature->SetField(addname_opt[iname].c_str(),addvalue_opt[iname].c_str());
break;
default:
+ std::cerr << "Error: field type not supported" << std::endl;
+ exit(1);
break;
}
- OGRFeature::DestroyFeature( poFeature );
}
CPLErrorReset();
if(verbose_opt[0])
@@ -182,6 +212,7 @@ int main(int argc, char *argv[])
poFeature->GetFID(), ogrWriter.getLayerName().c_str() );
OGRFeature::DestroyFeature( poDstFeature );
}
+ OGRFeature::DestroyFeature( poFeature );
OGRFeature::DestroyFeature( poDstFeature );
}
if(verbose_opt[0])
diff --git a/src/apps/pkegcs.cc b/src/apps/pkegcs.cc
index c7fa5f8..79f362b 100644
--- a/src/apps/pkegcs.cc
+++ b/src/apps/pkegcs.cc
@@ -28,8 +28,8 @@ int main(int argc, char *argv[])
Optionpk<string> cell2bb_opt("c2b","cell2bb","convert cell code to geo coordinates of boundingbox (e.g. 32-AB)","");
Optionpk<string> cell2mid_opt("c2m","cell2mid","convert cell code to centre in geo coordinates (e.g. 32-AB)","");
Optionpk<bool> refpixel_opt("\0", "ref", "get reference pixel (lower left corner of centre of gravity pixel)", false);
- Optionpk<double> maskValue_opt("m", "mask", "mask value(s) for no data to calculate reference pixel in image (Default is 0)",0);
- Optionpk<int> dx_opt("dx","dx","resolution (default is 250m)",250);
+ Optionpk<double> maskValue_opt("m", "mask", "mask value(s) for no data to calculate reference pixel in image",0);
+ Optionpk<int> dx_opt("dx","dx","resolution",250);
Optionpk<bool> geo2cell_opt("g2c", "geo2cell", "get cell code for coordinates in x_opt and y_opt given the resolution in dx_opt", false);
Optionpk<double> x_opt("x","x","x coordinate in epsg:3035",0);
Optionpk<double> y_opt("y","y","y coordinate in epsg:3035",0);
diff --git a/src/apps/pkfs_svm.cc b/src/apps/pkfs_svm.cc
index 1277e1f..a393062 100644
--- a/src/apps/pkfs_svm.cc
+++ b/src/apps/pkfs_svm.cc
@@ -33,7 +33,7 @@ enum SelectorValue { NA=0, SFFS=1, SFS=2, SBS=3, BFS=4 };
//global parameters used in cost function getCost
Optionpk<unsigned short> svm_type_opt("svmt", "svmtype", "type of SVM (0: C-SVC, 1: nu-SVC, 2: one-class SVM, 3: epsilon-SVR, 4: nu-SVR)",0);
-Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*|u-v|^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
+Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*(u-v)^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
Optionpk<unsigned short> kernel_degree_opt("kd", "kd", "degree in kernel function",3);
Optionpk<float> gamma_opt("g", "gamma", "gamma in kernel function",0);
Optionpk<float> coef0_opt("c0", "coef0", "coef0 in kernel function",0);
diff --git a/src/apps/pklas2img.cc b/src/apps/pklas2img.cc
index fd330a2..78f32da 100644
--- a/src/apps/pklas2img.cc
+++ b/src/apps/pklas2img.cc
@@ -29,34 +29,34 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
int main(int argc,char **argv) {
Optionpk<string> input_opt("i", "input", "Input las file", "");
// Optionpk<string> mask_opt("m", "mask", "mask image file", "");
- // Optionpk<short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use multiple values for a single mask. Default value is 0", 0);
- Optionpk<short> flag_opt("f", "flag", "Flag value(s) to put in image if not valid. Use as many flags as invalid options (Default is 0)", 0);
- Optionpk<string> attribute_opt("n", "name", "names of the attribute to select: [intensity|return|nreturn|z]", "z");
- Optionpk<bool> disc_opt("circ", "circular", "circular disc kernel for dilation and erosion (default is false)", false);
- Optionpk<double> maxSlope_opt("s", "maxSlope", "Maximum slope used for morphological filtering (default is 0)", 0.0);
+ // Optionpk<short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use multiple values for a single mask.", 0);
+ Optionpk<short> flag_opt("f", "flag", "Flag value(s) to put in image if not valid. Use as many flags as invalid options", 0);
+ Optionpk<string> attribute_opt("n", "name", "names of the attribute to select: intensity, return, nreturn, z", "z");
+ Optionpk<bool> disc_opt("circ", "circular", "circular disc kernel for dilation and erosion", false);
+ Optionpk<double> maxSlope_opt("s", "maxSlope", "Maximum slope used for morphological filtering", 0.0);
Optionpk<double> hThreshold_opt("ht", "maxHeight", "initial and maximum height threshold for progressive morphological filtering (e.g., -ht 0.2 -ht 2.5)", 0.2);
- Optionpk<short> maxIter_opt("\0", "maxIter", "Maximum number of iterations in post filter (default is 100)", 100.0);
- Optionpk<short> nbin_opt("nb", "nbin", "Number of percentile bins for calculating profile (=number of output bands) (default is 10)", 10.0);
+ Optionpk<short> maxIter_opt("\0", "maxIter", "Maximum number of iterations in post filter", 100.0);
+ Optionpk<short> nbin_opt("nb", "nbin", "Number of percentile bins for calculating profile (=number of output bands)", 10.0);
Optionpk<unsigned short> returns_opt("r", "returns", "number(s) of returns to include");
Optionpk<unsigned short> classes_opt("c", "classes", "classes to keep: 0 (created, never classified), 1 (unclassified), 2 (ground), 3 (low vegetation), 4 (medium vegetation), 5 (high vegetation), 6 (building), 7 (low point, noise), 8 (model key-point), 9 (water), 10 (reserved), 11 (reserved), 12 (overlap)");
- Optionpk<string> composite_opt("comp", "comp", "composite for multiple points in cell (min, max, median, mean, sum, first, last, profile, number (point density)). Default is last (overwrite cells with latest point", "last");
- Optionpk<string> filter_opt("fir", "filter", "filter las points (last,single,multiple,all). Default is all", "all");
- Optionpk<string> postFilter_opt("pf", "pfilter", "post processing filter (etew_min,promorph (progressive morphological filter),bunting (adapted promorph),open,close,none) . Default is none", "none");
- Optionpk<short> dimx_opt("\0", "dimX", "Dimension X of postFilter (default is 3)", 3);
- Optionpk<short> dimy_opt("\0", "dimY", "Dimension Y of postFilter (default is 3)", 3);
+ Optionpk<string> composite_opt("comp", "comp", "composite for multiple points in cell (min, max, median, mean, sum, first, last, profile, number (point density)). Last: overwrite cells with latest point", "last");
+ Optionpk<string> filter_opt("fir", "filter", "filter las points (last,single,multiple,all).", "all");
+ Optionpk<string> postFilter_opt("pf", "pfilter", "post processing filter (etew_min,promorph (progressive morphological filter),bunting (adapted promorph),open,close,none).", "none");
+ Optionpk<short> dimx_opt("\0", "dimX", "Dimension X of postFilter", 3);
+ Optionpk<short> dimy_opt("\0", "dimY", "Dimension Y of postFilter", 3);
Optionpk<string> output_opt("o", "output", "Output image file", "");
- Optionpk<string> projection_opt("p", "projection", "projection in EPSG code, e.g., EPSG:3035 (Default is no projection)", "");
- Optionpk<double> ulx_opt("\0", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
- Optionpk<double> uly_opt("\0", "uly", "Upper left y value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
- Optionpk<double> lrx_opt("\0", "lrx", "Lower right x value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
- Optionpk<double> lry_opt("\0", "lry", "Lower right y value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
+ Optionpk<string> projection_opt("p", "projection", "projection in EPSG code, e.g., EPSG:3035", "");
+ Optionpk<double> ulx_opt("\0", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true). 0 is read from input file", 0.0);
+ Optionpk<double> uly_opt("\0", "uly", "Upper left y value bounding box (in geocoordinates if georef is true). 0 is read from input file", 0.0);
+ Optionpk<double> lrx_opt("\0", "lrx", "Lower right x value bounding box (in geocoordinates if georef is true). 0 is read from input file", 0.0);
+ Optionpk<double> lry_opt("\0", "lry", "Lower right y value bounding box (in geocoordinates if georef is true). 0 is read from input file", 0.0);
Optionpk<string> otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "Byte");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter)", 1.0);
Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter)", 1.0);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
- Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode", 0);
bool doProcess;//stop process when program was invoked with help option (-h --help)
try{
diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc
index bda887e..4aab3fb 100644
--- a/src/apps/pkndvi.cc
+++ b/src/apps/pkndvi.cc
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
Optionpk<string> input_opt("i","input","input image file","");
Optionpk<string> output_opt("o","output","output image file containing ndvi","");
Optionpk<short> band_opt("b", "band", "Bands to be used for vegetation index (see rule option)", 0);
- Optionpk<string> rule_opt("r", "rule", "Rule for index. [ndvi (b1-b0)/(b1+b0)|ndvi2 (b1-b0)/(b2+b3)|gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02)))|vari (b1-b2)/(b1+b2-b0)|osavi|mcari|tcari|diff (b1-b0)|scale|ratio.", "ndvi");
+ Optionpk<string> rule_opt("r", "rule", "Rule for index. ndvi (b1-b0)/(b1+b0), ndvi2 (b1-b0)/(b2+b3), gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02))), vari (b1-b2)/(b1+b2-b0), osavi, mcari, tcari, diff (b1-b0), scale, ratio.", "ndvi");
Optionpk<double> invalid_opt("t", "invalid", "Mask value where image is invalid.", 0);
Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
diff --git a/src/apps/pkopt_svm.cc b/src/apps/pkopt_svm.cc
index ea2b9da..903f046 100644
--- a/src/apps/pkopt_svm.cc
+++ b/src/apps/pkopt_svm.cc
@@ -37,7 +37,7 @@ double objFunction(const std::vector<double> &x, std::vector<double> &grad, void
//global parameters used in objective function
Optionpk<unsigned short> svm_type_opt("svmt", "svmtype", "type of SVM (0: C-SVC, 1: nu-SVC, 2: one-class SVM, 3: epsilon-SVR, 4: nu-SVR)",0);
-Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*|u-v|^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
+Optionpk<unsigned short> kernel_type_opt("kt", "kerneltype", "type of kernel function (0: linear: u'*v, 1: polynomial: (gamma*u'*v + coef0)^degree, 2: radial basis function: exp(-gamma*(u-v)^2), 3: sigmoid: tanh(gamma*u'*v + coef0), 4: precomputed kernel (kernel values in training_set_file)",2);
Optionpk<unsigned short> kernel_degree_opt("kd", "kd", "degree in kernel function",3);
Optionpk<float> coef0_opt("c0", "coef0", "coef0 in kernel function",0);
Optionpk<float> nu_opt("nu", "nu", "the parameter nu of nu-SVC, one-class SVM, and nu-SVR",0.5);
diff --git a/src/base/PosValue.h b/src/base/IndexValue.h
similarity index 70%
copy from src/base/PosValue.h
copy to src/base/IndexValue.h
index 8ae957f..02f2482 100644
--- a/src/base/PosValue.h
+++ b/src/base/IndexValue.h
@@ -1,5 +1,5 @@
/**********************************************************************
-PosValue.h: class to work with structs containing a position and a value
+IndexValue.h: class to work with structs containing an index and a value
Copyright (C) 2008-2012 Pieter Kempeneers
This file is part of pktools
@@ -17,31 +17,31 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pktools. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
-#ifndef _POSVALUE_H_
-#define _POSVALUE_H_
+#ifndef _INDEXVALUE_H_
+#define _INDEXVALUE_H_
using namespace std;
-struct PosValue{
+struct IndexValue{
int position;
double value;
};
-class Compare_PosValue{
+class Compare_IndexValue{
public:
- int operator() (const PosValue& pv1, const PosValue& pv2) const{
+ int operator() (const IndexValue& pv1, const IndexValue& pv2) const{
return pv1.value>pv2.value;//for decreasing order
}
};
-class Decrease_PosValue{
+class Decrease_IndexValue{
public:
- int operator() (const PosValue& pv1, const PosValue& pv2) const{
+ int operator() (const IndexValue& pv1, const IndexValue& pv2) const{
return pv1.value>pv2.value;//for decreasing order
}
};
-class Increase_PosValue{
+class Increase_IndexValue{
public:
- int operator() (const PosValue& pv1, const PosValue& pv2) const{
+ int operator() (const IndexValue& pv1, const IndexValue& pv2) const{
return pv1.value<pv2.value;//for increasing order
}
};
-#endif /* _POSVALUE_H_ */
+#endif /* _INDEXVALUE_H_ */
diff --git a/src/base/PosValue.h b/src/base/PosValue.h
index 8ae957f..3a9856f 100644
--- a/src/base/PosValue.h
+++ b/src/base/PosValue.h
@@ -23,7 +23,8 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
using namespace std;
struct PosValue{
- int position;
+ double posx;
+ double posy;
double value;
};
class Compare_PosValue{
diff --git a/src/base/Vector2d.h b/src/base/Vector2d.h
index 7ff85b2..4b18e71 100644
--- a/src/base/Vector2d.h
+++ b/src/base/Vector2d.h
@@ -25,7 +25,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <algorithm>
#include <numeric>
#include <gsl/gsl_matrix.h>
-#include "PosValue.h"
+#include "IndexValue.h"
#include "algorithms/Histogram.h"
using namespace std;
@@ -200,14 +200,14 @@ template<class T> void Vector2d<T>::sort(Vector2d<T>& output)
//sort according to first sample (ex. wavelength)
int nsample=this->size();//including first sample (ex. wavelength)
int nband=(*this)[0].size();
- vector<PosValue> sortW(nband);
+ vector<IndexValue> sortW(nband);
for(int ilevel=0;ilevel<nband;++ilevel){
- PosValue pv;
+ IndexValue pv;
pv.position=ilevel;
pv.value=(*this)[0][ilevel];
sortW[ilevel]=pv;
}
- std::sort(sortW.begin(),sortW.end(),Increase_PosValue());
+ std::sort(sortW.begin(),sortW.end(),Increase_IndexValue());
output.resize(nsample);
for(int isample=0;isample<nsample;++isample){
output[isample].resize(nband);
diff --git a/src/imageclasses/ImgWriterOgr.cc b/src/imageclasses/ImgWriterOgr.cc
index 48955cf..15172d9 100644
--- a/src/imageclasses/ImgWriterOgr.cc
+++ b/src/imageclasses/ImgWriterOgr.cc
@@ -96,6 +96,14 @@ ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, b
//---------------------------------------------------------------------------
+void ImgWriterOgr::open(const string& filename, ImgReaderOgr& imageReader)
+{
+ m_filename=filename;
+ setCodec(imageReader.getDriver());
+ createLayer(filename,imageReader.getProjection(),imageReader.getGeometryType(),NULL);
+ copyFields(imageReader);
+}
+
void ImgWriterOgr::open(const string& filename, const string& imageType)
{
m_filename = filename;
diff --git a/src/imageclasses/ImgWriterOgr.h b/src/imageclasses/ImgWriterOgr.h
index c512945..004a1d7 100644
--- a/src/imageclasses/ImgWriterOgr.h
+++ b/src/imageclasses/ImgWriterOgr.h
@@ -42,6 +42,7 @@ public:
ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr);
ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, bool copyData);
~ImgWriterOgr(void);
+ void open(const string& filename, ImgReaderOgr& imgReaderOgr);
void open(const string& filename, const string& imageType="ESRI Shapefile");
void close(void);
int ascii2ogr(const string& filename, const string &layername, const vector<string>& fieldName, const vector<OGRFieldType>& fieldType, short colX=1, short colY=2, const string& theProjection="", const OGRwkbGeometryType& eGType=wkbPoint, const char fs=' ');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git
More information about the Pkg-grass-devel
mailing list