25 #include <sys/types.h>
27 #include "base/Optionpk.h"
28 #include "base/Vector2d.h"
29 #include "algorithms/Filter2d.h"
30 #include "algorithms/Filter.h"
31 #include "fileclasses/FileReaderAscii.h"
32 #include "imageclasses/ImgReaderGdal.h"
33 #include "imageclasses/ImgWriterGdal.h"
35 #include "algorithms/StatFactory.h"
41 int main(
int argc,
char **argv) {
45 Optionpk<bool> disc_opt(
"circ",
"circular",
"circular disc kernel for dilation and erosion",
false);
47 Optionpk<std::string> method_opt(
"f",
"filter",
"filter function (median, var, min, max, sum, mean, dilate, erode, close, open, homog (central pixel must be identical to all other pixels within window), heterog (central pixel must be different than all other pixels within window), sobelx (horizontal edge detection), sobely (vertical edge detection), sobelxy (diagonal edge detection NE-SW),sobelyx (diagonal edge detection NW-SE), smooth, density, countid, mode (majority voting, only for classes), smoothnodata (smooth nodata values only) values, threshold local filtering, ismin, ismax, order (rank pixels in order), stdev, mrf, dwt, dwti, dwt_cut, dwt_cut_from, scramble, shift, savgolay, percentile)");
48 Optionpk<std::string> resample_opt(
"r",
"resampling-method",
"Resampling method for shifting operation (near: nearest neighbour, bilinear: bi-linear interpolation).",
"near");
49 Optionpk<double> dimX_opt(
"dx",
"dx",
"filter kernel size in x, better use odd value to avoid image shift", 3);
50 Optionpk<double> dimY_opt(
"dy",
"dy",
"filter kernel size in y, better use odd value to avoid image shift", 3);
51 Optionpk<int> dimZ_opt(
"dz",
"dz",
"filter kernel size in z (spectral/temporal dimension), must be odd (example: 3).. Set dz>0 if 1-D filter must be used in band domain");
52 Optionpk<std::string> wavelet_type_opt(
"wt",
"wavelet",
"wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered",
"daubechies");
53 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);
54 Optionpk<int> savgolay_nl_opt(
"nl",
"nl",
"Number of leftward (past) data points used in Savitzky-Golay filter)", 2);
55 Optionpk<int> savgolay_nr_opt(
"nr",
"nr",
"Number of rightward (future) data points used in Savitzky-Golay filter)", 2);
56 Optionpk<int> savgolay_ld_opt(
"ld",
"ld",
"order of the derivative desired in Savitzky-Golay filter (e.g., ld=0 for smoothed function)", 0);
57 Optionpk<int> savgolay_m_opt(
"m",
"m",
"order of the smoothing polynomial in Savitzky-Golay filter, also equal to the highest conserved moment; usual values are m = 2 or m = 4)", 2);
58 Optionpk<short> class_opt(
"class",
"class",
"class value(s) to use for density, erosion, dilation, openening and closing, thresholding");
59 Optionpk<double> threshold_opt(
"t",
"threshold",
"threshold value(s) to use for threshold filter (one for each class), or threshold to cut for dwt_cut (use 0 to keep all) or dwt_cut_from, or sigma for shift", 0);
60 Optionpk<double> nodata_opt(
"nodata",
"nodata",
"nodata value(s) (used for smoothnodata filter)");
61 Optionpk<std::string> tap_opt(
"tap",
"tap",
"text file containing taps used for spatial filtering (from ul to lr). Use dimX and dimY to specify tap dimensions in x and y. Leave empty for not using taps");
62 Optionpk<double> tapz_opt(
"tapz",
"tapz",
"taps used for spectral filtering");
63 Optionpk<string> padding_opt(
"pad",
"pad",
"Padding method for filtering (how to handle edge effects). Choose between: symmetric, replicate, circular, zero (pad with 0).",
"symmetric");
64 Optionpk<double> fwhm_opt(
"fwhm",
"fwhm",
"list of full width half to apply spectral filtering (-fwhm band1 -fwhm band2 ...)");
65 Optionpk<std::string> srf_opt(
"srf",
"srf",
"list of ASCII files containing spectral response functions (two columns: wavelength response)");
66 Optionpk<double> wavelengthIn_opt(
"win",
"wavelengthIn",
"list of wavelengths in input spectrum (-win band1 -win band2 ...)");
67 Optionpk<double> wavelengthOut_opt(
"wout",
"wavelengthOut",
"list of wavelengths in output spectrum (-wout band1 -wout band2 ...)");
68 Optionpk<std::string> interpolationType_opt(
"interp",
"interp",
"type of interpolation for spectral filtering (see http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html)",
"akima");
69 Optionpk<std::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",
"");
70 Optionpk<string> oformat_opt(
"of",
"oformat",
"Output image format (see also gdal_translate). Empty string: inherit from input image");
71 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");
72 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
73 Optionpk<short> down_opt(
"d",
"down",
"down sampling factor. Use value 1 for no downsampling). Use value n>1 for downsampling (aggregation)", 1);
74 Optionpk<string> beta_opt(
"beta",
"beta",
"ASCII file with beta for each class transition in Markov Random Field");
80 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
82 resample_opt.setHide(1);
83 option_opt.setHide(1);
84 wavelet_type_opt.setHide(1);
85 family_opt.setHide(1);
86 savgolay_nl_opt.setHide(1);
87 savgolay_nr_opt.setHide(1);
88 savgolay_ld_opt.setHide(1);
89 savgolay_m_opt.setHide(1);
91 threshold_opt.setHide(1);
94 padding_opt.setHide(1);
95 wavelengthIn_opt.setHide(1);
96 wavelengthOut_opt.setHide(1);
104 interpolationType_opt.setHide(1);
105 otype_opt.setHide(1);
106 oformat_opt.setHide(1);
107 colorTable_opt.setHide(1);
112 doProcess=input_opt.retrieveOption(argc,argv);
113 output_opt.retrieveOption(argc,argv);
116 method_opt.retrieveOption(argc,argv);
117 srf_opt.retrieveOption(argc,argv);
118 fwhm_opt.retrieveOption(argc,argv);
119 dimX_opt.retrieveOption(argc,argv);
120 dimY_opt.retrieveOption(argc,argv);
121 dimZ_opt.retrieveOption(argc,argv);
122 nodata_opt.retrieveOption(argc,argv);
123 resample_opt.retrieveOption(argc,argv);
124 option_opt.retrieveOption(argc,argv);
125 wavelet_type_opt.retrieveOption(argc,argv);
126 family_opt.retrieveOption(argc,argv);
127 savgolay_nl_opt.retrieveOption(argc,argv);
128 savgolay_nr_opt.retrieveOption(argc,argv);
129 savgolay_ld_opt.retrieveOption(argc,argv);
130 savgolay_m_opt.retrieveOption(argc,argv);
131 class_opt.retrieveOption(argc,argv);
132 threshold_opt.retrieveOption(argc,argv);
133 tap_opt.retrieveOption(argc,argv);
134 tapz_opt.retrieveOption(argc,argv);
135 padding_opt.retrieveOption(argc,argv);
136 wavelengthIn_opt.retrieveOption(argc,argv);
137 wavelengthOut_opt.retrieveOption(argc,argv);
138 down_opt.retrieveOption(argc,argv);
139 beta_opt.retrieveOption(argc,argv);
145 interpolationType_opt.retrieveOption(argc,argv);
146 otype_opt.retrieveOption(argc,argv);
147 oformat_opt.retrieveOption(argc,argv);
148 colorTable_opt.retrieveOption(argc,argv);
149 disc_opt.retrieveOption(argc,argv);
150 verbose_opt.retrieveOption(argc,argv);
152 catch(
string predefinedString){
153 std::cout << predefinedString << std::endl;
158 cout <<
"Usage: pkfilter -i input -o ouptut [-f filter | -perc value | -srf file [-srf file]* -win wavelength [-win wavelength]* | -wout wavelength -fwhm value [-wout wavelength -fwhm value]* -win wavelength [-win wavelength]*]" << endl;
160 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
165 vector<double> angle_opt;
169 if(input_opt.empty()){
170 cerr <<
"Error: no input file selected, use option -i" << endl;
173 if(output_opt.empty()){
174 cerr <<
"Error: no output file selected, use option -o" << endl;
177 input.open(input_opt[0]);
178 GDALDataType theType=GDT_Unknown;
180 cout <<
"possible output data types: ";
181 for(
int iType = 0; iType < GDT_TypeCount; ++iType){
183 cout <<
" " << GDALGetDataTypeName((GDALDataType)iType);
184 if( GDALGetDataTypeName((GDALDataType)iType) != NULL
185 && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
186 otype_opt[0].c_str()))
187 theType=(GDALDataType) iType;
189 if(theType==GDT_Unknown)
190 theType=input.getDataType();
193 std::cout << std::endl <<
"Output pixel type: " << GDALGetDataTypeName(theType) << endl;
195 string imageType=input.getImageType();
196 if(oformat_opt.size())
197 imageType=oformat_opt[0];
199 if(option_opt.findSubstring(
"INTERLEAVE=")==option_opt.end()){
200 string theInterleave=
"INTERLEAVE=";
201 theInterleave+=input.getInterleave();
202 option_opt.push_back(theInterleave);
205 int nband=input.nrOfBand();
208 nband=fwhm_opt.size();
209 else if(srf_opt.size())
210 nband=srf_opt.size();
211 else if(tap_opt.size()||tapz_opt.size())
212 nband=input.nrOfBand();
214 if(method_opt.empty()){
215 cerr <<
"Error: no filter selected, use option -f" << endl;
218 switch(filter2d::Filter2d::getFilterType(method_opt[0])){
219 case(filter2d::dilate):
220 case(filter2d::erode):
221 case(filter2d::close):
222 case(filter2d::open):
223 case(filter2d::smooth):
226 assert(dimZ_opt[0]>1);
227 nband=input.nrOfBand();
230 case(filter2d::dwti):
231 case(filter2d::dwt_cut):
232 case(filter2d::smoothnodata):
234 nband=input.nrOfBand();
236 case(filter2d::savgolay):
237 nband=input.nrOfBand();
239 dimZ_opt.push_back(1);
240 case(filter2d::dwt_cut_from):
243 nband=input.nrOfBand();
244 assert(threshold_opt.size());
247 cerr <<
"filter not implemented in spectral/temporal domain" << endl;
252 assert(class_opt.size()>1);
254 std::cout <<
"opening output image " << output_opt[0] << std::endl;
255 nband=class_opt.size();
256 case(filter2d::ismin):
257 case(filter2d::ismax):
258 case(filter2d::shift):
259 case(filter2d::scramble):
260 case(filter2d::mode):
261 case(filter2d::sobelx):
262 case(filter2d::sobely):
263 case(filter2d::sobelxy):
264 case(filter2d::countid):
265 case(filter2d::order):
266 case(filter2d::density):
267 case(filter2d::homog):
268 case(filter2d::heterog):
271 cerr <<
"filter not implemented in spectral/temporal domain" << endl;
285 case(filter2d::mean):
289 case(filter2d::stdev):
290 case(filter2d::median):
291 case(filter2d::percentile):
293 if(dimZ_opt.size()==1)
297 nband=input.nrOfBand();
300 cerr <<
"filter not implemented" << endl;
309 std::cout <<
"opening output image " << output_opt[0] <<
" with " << nband <<
" bands" << std::endl;
310 output.open(output_opt[0],(input.nrOfCol()+down_opt[0]-1)/down_opt[0],(input.nrOfRow()+down_opt[0]-1)/down_opt[0],nband,theType,imageType,option_opt);
312 catch(
string errorstring){
313 cout << errorstring << endl;
316 output.setProjection(input.getProjection());
318 input.getGeoTransform(gt);
321 output.setGeoTransform(gt);
323 if(colorTable_opt.size()){
324 if(colorTable_opt[0]!=
"none"){
326 cout <<
"set colortable " << colorTable_opt[0] << endl;
327 assert(output.getDataType()==GDT_Byte);
328 output.setColorTable(colorTable_opt[0]);
331 else if(input.getColorTable()!=NULL)
332 output.setColorTable(input.getColorTable());
334 if(nodata_opt.size()){
335 for(
int iband=0;iband<output.nrOfBand();++iband)
336 output.GDALSetNoDataValue(nodata_opt[0],iband);
342 cout <<
"Set padding to " << padding_opt[0] << endl;
343 filter1d.setPadding(padding_opt[0]);
344 if(class_opt.size()){
346 std::cout<<
"class values: ";
347 for(
int iclass=0;iclass<class_opt.size();++iclass){
349 filter2d.pushClass(class_opt[iclass]);
351 filter1d.pushClass(class_opt[iclass]);
353 std::cout<< class_opt[iclass] <<
" ";
356 std::cout<< std::endl;
359 if(nodata_opt.size()){
361 std::cout<<
"mask values: ";
362 for(
int imask=0;imask<nodata_opt.size();++imask){
364 std::cout<< nodata_opt[imask] <<
" ";
365 filter1d.pushNoDataValue(nodata_opt[imask]);
366 filter2d.pushNoDataValue(nodata_opt[imask]);
369 std::cout<< std::endl;
372 ifstream tapfile(tap_opt[0].c_str());
376 for(
int j=0;j<dimY_opt[0];++j){
377 for(
int i=0;i<dimX_opt[0];++i){
378 tapfile >> taps[j][i];
382 std::cout <<
"taps: ";
383 for(
int j=0;j<dimY_opt[0];++j){
384 for(
int i=0;i<dimX_opt[0];++i){
385 std::cout<< taps[j][i] <<
" ";
387 std::cout<< std::endl;
390 filter2d.setTaps(taps);
392 filter2d.filter(input,output);
394 catch(
string errorstring){
395 cerr << errorstring << endl;
399 else if(tapz_opt.size()){
401 std::cout <<
"taps: ";
402 for(
int itap=0;itap<tapz_opt.size();++itap)
403 std::cout<< tapz_opt[itap] <<
" ";
404 std::cout<< std::endl;
406 filter1d.setTaps(tapz_opt);
407 filter1d.filter(input,output);
409 else if(fwhm_opt.size()){
411 std::cout <<
"spectral filtering to " << fwhm_opt.size() <<
" bands with provided fwhm " << std::endl;
412 assert(wavelengthOut_opt.size()==fwhm_opt.size());
413 assert(wavelengthIn_opt.size());
417 const char* pszMessage;
418 void* pProgressArg=NULL;
419 GDALProgressFunc pfnProgress=GDALTermProgress;
421 pfnProgress(progress,pszMessage,pProgressArg);
422 for(
int y=0;y<input.nrOfRow();++y){
423 if((y+1+down_opt[0]/2)%down_opt[0])
425 for(
int iband=0;iband<input.nrOfBand();++iband)
426 input.readData(lineInput[iband],GDT_Float64,y,iband);
427 filter1d.applyFwhm<
double>(wavelengthIn_opt,lineInput,wavelengthOut_opt,fwhm_opt, interpolationType_opt[0], lineOutput, down_opt[0], verbose_opt[0]);
428 for(
int iband=0;iband<output.nrOfBand();++iband){
430 output.writeData(lineOutput[iband],GDT_Float64,y/down_opt[0],iband);
432 catch(
string errorstring){
433 cerr << errorstring <<
"in band " << iband <<
", line " << y << endl;
436 progress=(1.0+y)/output.nrOfRow();
437 pfnProgress(progress,pszMessage,pProgressArg);
440 else if(srf_opt.size()){
442 std::cout <<
"spectral filtering to " << srf_opt.size() <<
" bands with provided SRF " << std::endl;
443 assert(wavelengthIn_opt.size());
444 vector< Vector2d<double> > srf(srf_opt.size());
446 for(
int isrf=0;isrf<srf_opt.size();++isrf){
448 srfFile.open(srf_opt[isrf].c_str());
451 srf[isrf][0].push_back(0);
452 srf[isrf][1].push_back(0);
453 srf[isrf][0].push_back(1);
454 srf[isrf][1].push_back(0);
456 srf[isrf][0].push_back(v);
458 srf[isrf][1].push_back(v);
462 srf[isrf][0].push_back(srf[isrf][0].back()+1);
463 srf[isrf][1].push_back(0);
464 srf[isrf][0].push_back(srf[isrf][0].back()+1);
465 srf[isrf][1].push_back(0);
467 cout <<
"srf file details: " << srf[isrf][0].size() <<
" wavelengths defined" << endl;
469 assert(output.nrOfBand()==srf.size());
470 double centreWavelength=0;
472 const char* pszMessage;
473 void* pProgressArg=NULL;
474 GDALProgressFunc pfnProgress=GDALTermProgress;
476 pfnProgress(progress,pszMessage,pProgressArg);
477 for(
int y=0;y<input.nrOfRow();++y){
478 if((y+1+down_opt[0]/2)%down_opt[0])
480 for(
int iband=0;iband<input.nrOfBand();++iband)
481 input.readData(lineInput[iband],GDT_Float64,y,iband);
482 for(
int isrf=0;isrf<srf.size();++isrf){
483 vector<double> lineOutput(output.nrOfCol());
486 centreWavelength=filter1d.applySrf<
double>(wavelengthIn_opt,lineInput,srf[isrf], interpolationType_opt[0], lineOutput, delta, normalize);
488 std::cout <<
"centre wavelength srf " << isrf <<
": " << centreWavelength << std::endl;
490 output.writeData(lineOutput,GDT_Float64,y/down_opt[0],isrf);
492 catch(
string errorstring){
493 cerr << errorstring <<
"in srf " << srf_opt[isrf] <<
", line " << y << endl;
497 progress=(1.0+y)/output.nrOfRow();
498 pfnProgress(progress,pszMessage,pProgressArg);
503 switch(filter2d::Filter2d::getFilterType(method_opt[0])){
504 case(filter2d::dilate):
506 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
512 std::cout<<
"1-D filtering: dilate" << std::endl;
513 filter1d.morphology(input,output,
"dilate",dimZ_opt[0],verbose_opt[0]);
516 filter2d.morphology(input,output,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
518 catch(
string errorstring){
519 cerr << errorstring << endl;
522 case(filter2d::erode):
524 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
528 if(dimZ_opt.size()>0){
530 std::cout<<
"1-D filtering: dilate" << std::endl;
531 filter1d.morphology(input,output,
"erode",dimZ_opt[0]);
534 filter2d.morphology(input,output,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
537 catch(
string errorstring){
538 cerr << errorstring << endl;
541 case(filter2d::close):{
543 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
548 tmpout.open(
"/vsimem/dilation.tif",input);
551 filter1d.morphology(input,tmpout,
"dilate",dimZ_opt[0]);
554 filter2d.morphology(input,tmpout,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
557 catch(std::string errorString){
558 std::cout<< errorString;
562 tmpin.open(
"/vsimem/dilation.tif");
565 filter1d.morphology(tmpin,output,
"erode",dimZ_opt[0]);
568 filter2d.morphology(tmpin,output,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
571 catch(
string errorstring){
572 cerr << errorstring << endl;
578 case(filter2d::open):{
580 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
584 tmpout.open(
"/vsimem/erosion.tif",input);
587 filter1d.morphology(input,tmpout,
"erode",dimZ_opt[0]);
590 filter2d.morphology(input,tmpout,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
593 catch(std::string errorString){
594 std::cout<< errorString;
599 tmpin.open(
"/vsimem/erosion.tif");
601 filter1d.morphology(tmpin,output,
"dilate",dimZ_opt[0]);
604 filter2d.morphology(tmpin,output,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
609 catch(
string errorstring){
610 cerr << errorstring << endl;
614 case(filter2d::homog):{
616 filter2d.doit(input,output,
"homog",dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
618 catch(
string errorstring){
619 cerr << errorstring << endl;
623 case(filter2d::heterog):{
625 filter2d.doit(input,output,
"heterog",dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
627 catch(
string errorstring){
628 cerr << errorstring << endl;
632 case(filter2d::shift):{
634 std::cerr <<
"Error: down option not supported for shift operator" << std::endl;
637 assert(input.nrOfBand());
638 assert(input.nrOfCol());
639 assert(input.nrOfRow());
641 filter2d.shift(input,output,dimX_opt[0],dimY_opt[0],threshold_opt[0],filter2d::Filter2d::getResampleType(resample_opt[0]));
643 catch(
string errorstring){
644 cerr << errorstring << endl;
670 case(filter2d::mrf):{
672 std::cout <<
"Markov Random Field filtering" << std::endl;
679 vector<int> cols(class_opt.size());
680 for(
int iclass=0;iclass<class_opt.size();++iclass)
682 betaReader.readData(beta,cols);
684 std::cout <<
"using values for beta:" << std::endl;
685 for(
int iclass1=0;iclass1<class_opt.size();++iclass1)
686 std::cout <<
" " << iclass1 <<
" (" << class_opt[iclass1] <<
")";
687 std::cout << std::endl;
688 for(
int iclass1=0;iclass1<class_opt.size();++iclass1){
689 std::cout << iclass1 <<
" (" << class_opt[iclass1] <<
")";
690 for(
int iclass2=0;iclass2<class_opt.size();++iclass2)
691 std::cout <<
" " << beta[iclass2][iclass1] <<
" (" << class_opt[iclass2] <<
")";
692 std::cout << std::endl;
695 filter2d.mrf(input, output, dimX_opt[0], dimY_opt[0], beta,
true, down_opt[0], verbose_opt[0]);
698 filter2d.mrf(input, output, dimX_opt[0], dimY_opt[0], 1,
true, down_opt[0], verbose_opt[0]);
700 catch(
string errorstring){
701 cerr << errorstring << endl;
705 case(filter2d::sobelx):{
707 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
720 filter2d.setTaps(theTaps);
722 filter2d.filter(input,output,
true,
true);
724 catch(
string errorstring){
725 cerr << errorstring << endl;
729 case(filter2d::sobely):{
731 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
744 filter2d.setTaps(theTaps);
746 filter2d.filter(input,output,
true,
true);
748 catch(
string errorstring){
749 cerr << errorstring << endl;
753 case(filter2d::sobelxy):{
755 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
768 filter2d.setTaps(theTaps);
770 filter2d.filter(input,output,
true,
true);
772 catch(
string errorstring){
773 cerr << errorstring << endl;
777 case(filter2d::sobelyx):{
779 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
792 filter2d.setTaps(theTaps);
794 filter2d.filter(input,output,
true,
true);
796 catch(
string errorstring){
797 cerr << errorstring << endl;
801 case(filter2d::smooth):{
803 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
809 std::cout<<
"1-D filtering: smooth" << std::endl;
810 filter1d.smooth(input,output,dimZ_opt[0]);
813 filter2d.smooth(input,output,dimX_opt[0],dimY_opt[0]);
816 catch(
string errorstring){
817 cerr << errorstring << endl;
821 case(filter2d::smoothnodata):{
823 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
829 std::cout<<
"1-D filtering: smooth" << std::endl;
830 filter1d.smoothNoData(input,interpolationType_opt[0],output);
834 std::cout<<
"2-D filtering: smooth" << std::endl;
835 filter2d.smoothNoData(input,output,dimX_opt[0],dimY_opt[0]);
838 catch(
string errorstring){
839 cerr << errorstring << endl;
845 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
851 std::cout<<
"DWT in spectral domain" << std::endl;
852 filter1d.dwtForward(input, output, wavelet_type_opt[0], family_opt[0]);
855 filter2d.dwtForward(input, output, wavelet_type_opt[0], family_opt[0]);
857 catch(
string errorstring){
858 cerr << errorstring << endl;
861 case(filter2d::dwti):
863 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
869 std::cout<<
"inverse DWT in spectral domain" << std::endl;
870 filter1d.dwtInverse(input, output, wavelet_type_opt[0], family_opt[0]);
873 filter2d.dwtInverse(input, output, wavelet_type_opt[0], family_opt[0]);
875 catch(
string errorstring){
876 cerr << errorstring << endl;
879 case(filter2d::dwt_cut):
881 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
886 std::cout<<
"DWT approximation in spectral domain" << std::endl;
887 filter1d.dwtCut(input, output, wavelet_type_opt[0], family_opt[0], threshold_opt[0]);
890 filter2d.dwtCut(input, output, wavelet_type_opt[0], family_opt[0], threshold_opt[0]);
892 case(filter2d::dwt_cut_from):
894 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
900 std::cout<<
"DWT approximation in spectral domain" << std::endl;
901 filter1d.dwtCutFrom(input, output, wavelet_type_opt[0], family_opt[0], static_cast<int>(threshold_opt[0]));
904 string errorString=
"Error: this filter is not supported in 2D";
908 catch(
string errorstring){
909 cerr << errorstring << endl;
912 case(filter2d::savgolay):{
913 assert(savgolay_nl_opt.size());
914 assert(savgolay_nr_opt.size());
915 assert(savgolay_ld_opt.size());
916 assert(savgolay_m_opt.size());
918 std::cout <<
"Calculating Savitzky-Golay coefficients: " << endl;
919 filter1d.getSavGolayCoefficients(tapz_opt, input.nrOfBand(), savgolay_nl_opt[0], savgolay_nr_opt[0], savgolay_ld_opt[0], savgolay_m_opt[0]);
921 std::cout <<
"taps (size is " << tapz_opt.size() <<
"): ";
922 for(
int itap=0;itap<tapz_opt.size();++itap)
923 std::cout<< tapz_opt[itap] <<
" ";
924 std::cout<< std::endl;
926 filter1d.setTaps(tapz_opt);
927 filter1d.filter(input,output);
930 case(filter2d::percentile):
931 case(filter2d::threshold):
932 assert(threshold_opt.size());
934 filter1d.setThresholds(threshold_opt);
936 filter2d.setThresholds(threshold_opt);
937 case(filter2d::density):
938 filter2d.setClasses(class_opt);
940 std::cout <<
"classes set" << std::endl;
945 filter1d.stat(input,output,method_opt[0]);
947 assert(down_opt[0]==1);
948 filter1d.filter(input,output,method_opt[0],dimZ_opt[0]);
952 filter2d.doit(input,output,method_opt[0],dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
954 catch(
string errorstring){
955 cerr << errorstring << endl;