[pktools] 135/375: getminmax before calc histogram in pkinfo.cc

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:54:07 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 e2f5e95c6f1df5788b50214c7400922f0cb56aa2
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Sun Nov 3 00:21:26 2013 +0100

    getminmax before calc histogram in pkinfo.cc
---
 ChangeLog                         |  7 +++++
 doc/examples_pksetmask.dox        | 35 ++++++++++++++++++----
 src/apps/Makefile.am              |  4 +--
 src/apps/pkfilter.cc              |  6 ++--
 src/apps/pkinfo.cc                |  3 ++
 src/imageclasses/ImgWriterGdal.cc | 63 ++++++++++++++++-----------------------
 6 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c948569..2951e1c 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -117,6 +117,10 @@ version 2.4.1
 	todo: take priors into account for cross validation
 	ordering of labels before training
 version 2.4.2
+ - todo: change all projection options to a_srs
+ - apps/Makefile.am
+	add GSL_LIBS to AM_LDFLAGS and LDADD
+	todo: remove redundancy in AM_LDFLAGS and LDADD
  - clean up of using namespace std in header files
  - FileReaderAscii
 	corrected error for constructor with fieldseparator argument
@@ -124,6 +128,9 @@ version 2.4.2
 	bug fixed with -min and -max in hist (thanks to Giuseppe Amatuli for noticing)
  - pkfilter
 	new methods for scrambling and shifting images
+	update help info for support of of even kernel sizes
+ - Filter2d
+	added support for even kernel sizes
  - pkstatogr
 	make histogram more similar to pkstat with support of relative option
  - pklas2img
diff --git a/doc/examples_pksetmask.dox b/doc/examples_pksetmask.dox
index 8c09eff..f152088 100644
--- a/doc/examples_pksetmask.dox
+++ b/doc/examples_pksetmask.dox
@@ -1,4 +1,32 @@
 \section examples_pksetmask Examples of pksetmask
+
+\section single_mask Using a single mask
+
+With a single mask you can provide as many triples (--operator, --invalid, --flag) as you wish. All operators work simultaneously on that mask. Caution: the first operator that tests true will be selected. This is explained in the next example:
+
+\code
+pksetmask -i input.tif -m mask.tif --operator='>' --invalid 0 --flag 0 --operator='>' --invalid 10 --flag 10 -o output.tif
+\endcode
+Warning: second operator will never test true as first will supersede!
+\code
+pksetmask -i input.tif -m mask.tif --operator='>' --invalid 10 --flag 10 --operator='>' --invalid 0 --flag 1 -output.tif
+\endcode
+OK: values above 10 will be 10, values between 0 and 10 will be 1
+
+\section multiple_masks Using multiple masks
+With multiple masks, you can use one triple (--operator, --invalid, --flag) for each corresponding mask (following the same order of input). If the number of triples is not equal to the number of masks, then only the first triple is used for all masks simultaneously
+\code
+pksetmask -i input.tif -m mask1.tif --operator '>' --invalid 250 --flag 1 -m mask2.tif --operator '>' --invalid 100 --flag 2 -o output.tif
+\endcode
+If mask1.tif is above 250, the output will be 1. If mask2 is above 100, the output will be 2. If both operators test true, the first will supersede (output will be 1)
+
+\code
+pksetmask -i input.tif -m mask1.tif -m mask1.tif --operator '>' --invalid 250 --flag 1 -o output.tif
+\endcode
+If either mask1.tif or mask2.tif is above 250, the output will be 1
+
+\section more_examples More examples
+
 \code
 pksetmask -i input.tif -m mask.tif -o output.tif -ot Byte -t 0 -f 255
 \endcode
@@ -17,9 +45,4 @@ Application of two masks. Copy pixel values from input.tif to output.tif, settin
 \code
 pksetmask -i input.tif -m mask.tif -o output.tif -ot Byte -t 0 -t 1 -f 255 -f 255
 \endcode
-copy pixel values from input.tif to output.tif, applying single masks, setting all values to 255 where mask is either 0 or 1.
-
-\code
-pksetmask -i input.tif -m mask.tif -o output.tif -ot Byte -t 0 -t 1 -f 255 -f 255
-\endcode
-copy pixel values from input.tif to output.tif, applying single masks, setting all values to 255 where mask is either 0 or 1.
+copy pixel values from input.tif to output.tif, applying single masks, setting all values to 255 where mask is either 0 or 1.
\ No newline at end of file
diff --git a/src/apps/Makefile.am b/src/apps/Makefile.am
index 2de9f1a..91e1db9 100644
--- a/src/apps/Makefile.am
+++ b/src/apps/Makefile.am
@@ -1,6 +1,6 @@
 AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/base $(GDAL_CFLAGS) @AM_CXXFLAGS@
-AM_LDFLAGS = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.la $(top_builddir)/src/imageclasses/libimageClasses.la $(top_builddir)/src/fileclasses/libfileClasses.la $(top_builddir)/src/base/libbase.la @AM_LDFLAGS@
-LDADD = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.la $(top_builddir)/src/imageclasses/libimageClasses.la $(top_builddir)/src/fileclasses/libfileClasses.la $(top_builddir)/src/base/libbase.la
+AM_LDFLAGS = $(GSL_LIBS) $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.la $(top_builddir)/src/imageclasses/libimageClasses.la $(top_builddir)/src/fileclasses/libfileClasses.la $(top_builddir)/src/base/libbase.la @AM_LDFLAGS@
+LDADD = $(GSL_LIBS) $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.la $(top_builddir)/src/imageclasses/libimageClasses.la $(top_builddir)/src/fileclasses/libfileClasses.la $(top_builddir)/src/base/libbase.la
 ###############################################################################
 # THE PROGRAMS TO BUILD
 ###############################################################################
diff --git a/src/apps/pkfilter.cc b/src/apps/pkfilter.cc
index eede73a..50350a4 100644
--- a/src/apps/pkfilter.cc
+++ b/src/apps/pkfilter.cc
@@ -43,8 +43,8 @@ int main(int argc,char **argv) {
   Optionpk<double> angle_opt("a", "angle", "angle used for directional filtering in dilation (North=0, East=90, South=180, West=270).");
   Optionpk<std::string> method_opt("f", "filter", "filter function (median,var,min,max,sum,mean,minmax,dilate,erode,close,open,spatially homogeneous (central pixel must be identical to all other pixels within window),SobelX edge detection in X,SobelY edge detection in Y,SobelXY,SobelYX,smooth,density,majority voting (only for classes),forest aggregation (mixed),smooth no data (mask) values,threshold local filtering,ismin,ismax,heterogeneous (central pixel must be different than all other [...]
   Optionpk<std::string> resample_opt("r", "resampling-method", "Resampling method for shifting operation (near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
-  Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, must be odd", 3);
-  Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, must be odd", 3);
+  Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, better use odd value to avoid image shift", 3);
+  Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, better use odd value to avoid image shift", 3);
   Optionpk<int> dimZ_opt("dz", "dz", "filter kernel size in z (band or spectral dimension), must be odd (example: 3).. Set dz>0 if 1-D filter must be used in band domain");
   Optionpk<std::string> wavelet_type_opt("wt", "wavelet", "wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered", "daubechies");
   Optionpk<int> family_opt("wf", "family", "wavelet family (vanishing moment, see also http://www.gnu.org/software/gsl/manual/html_node/DWT-Initialization.html)", 4);
@@ -62,7 +62,7 @@ int main(int argc,char **argv) {
   Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image");
   Optionpk<string>  colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid). Use none to ommit color table");
   Optionpk<std::string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]");
-  Optionpk<short> down_opt("d", "down", "down sampling factor. Use value 1 for no downsampling)", 1);
+  Optionpk<short> down_opt("d", "down", "down sampling factor. Use value 1 for no downsampling). Use value n>1 for downsampling (aggregation)", 1);
   Optionpk<string> beta_opt("beta", "beta", "ASCII file with beta for each class transition in Markov Random Field");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
 
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index 1ba22c5..6095ad8 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -293,6 +293,9 @@ int main(int argc, char *argv[])
       std::vector<unsigned long int> output(nbin_opt[0]);
       minValue=0;
       maxValue=0;
+      //todo: optimize such that getMinMax is only called once...
+      imgReader.getMinMax(minValue,maxValue,band_opt[0]);
+      
       if(min_opt.size())
         minValue=min_opt[0];
       if(max_opt.size())
diff --git a/src/imageclasses/ImgWriterGdal.cc b/src/imageclasses/ImgWriterGdal.cc
index 1f2bf65..a640268 100644
--- a/src/imageclasses/ImgWriterGdal.cc
+++ b/src/imageclasses/ImgWriterGdal.cc
@@ -293,47 +293,34 @@ string ImgWriterGdal::setProjectionProj4(const string& projection)
   if(!m_isGeoRef)
     m_isGeoRef=true;
 
-    OGRSpatialReferenceH hSRS;  
-    char *pszResult = NULL;  
+  OGRSpatialReference theRef;
+  theRef.SetFromUserInput(projection.c_str());
+  char *wktString;
+  theRef.exportToWkt(&wktString);
+  assert(m_gds);
+  m_gds->SetProjection(wktString);
+  return(wktString);
+
+    // OGRSpatialReferenceH hSRS;  
+    // char *pszResult = NULL;  
   
-    CPLErrorReset();  
+    // CPLErrorReset();  
       
-    hSRS = OSRNewSpatialReference( NULL );  
-    if( OSRSetFromUserInput( hSRS, projection.c_str() ) == OGRERR_NONE )  
-        OSRExportToWkt( hSRS, &pszResult );  
-    else  
-    {  
-        // CPLError( CE_Failure, CPLE_AppDefined,  
-        //           "Translating source or target SRS failed:\n%s",  
-        //           projection.c_str() );  
-        ostringstream s;
-        s << "Error in set projection " << projection;
-        throw(s.str());
-        // exit( 1 );
-    }  
-    // m_gds->SetProjection(pszResult);
-
-    //due to error in Gdal? AUTHORITY fields do not seem to work!
-    string theProjection=pszResult;
-    // size_t startpos,endpos;
-    // while((startpos=theProjection.find(",AUTHORITY"))!=string::npos){
-    //   endpos=theProjection.find("]",startpos+1,1)+1;
-    //   theProjection.erase(startpos,endpos-startpos);
-    // }
-    assert(m_gds);
-    m_gds->SetProjection(theProjection.c_str());
-    OSRDestroySpatialReference( hSRS );  
+    // hSRS = OSRNewSpatialReference( NULL );  
+    // if( OSRSetFromUserInput( hSRS, projection.c_str() ) == OGRERR_NONE )  
+    //     OSRExportToWkt( hSRS, &pszResult );  
+    // else  
+    // {  
+    //     ostringstream s;
+    //     s << "Error in set projection " << projection;
+    //     throw(s.str());
+    // }  
+    // string theProjection=pszResult;
+    // assert(m_gds);
+    // m_gds->SetProjection(theProjection.c_str());
+    // OSRDestroySpatialReference( hSRS );  
   
-    // return pszResult;  
-    return theProjection;  
-
-//   OGRSpatialReference oSRS;
-//   char *pszSRS_WKT = NULL;
-//   oSRS.importFromProj4(projection.c_str());
-// //   oSRS.SetLAEA(52,10,4321000,3210000);//redundant but according to JRC standard
-//   oSRS.exportToWkt(&pszSRS_WKT);
-//   m_gds->SetProjection(pszSRS_WKT);
-//   CPLFree(pszSRS_WKT);
+    // return theProjection;  
 }
 
 void ImgWriterGdal::setProjection(const string& projection)

-- 
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