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" 34 #include "algorithms/StatFactory.h" 229 int main(
int argc,
char **argv) {
233 Optionpk<bool> disc_opt(
"circ",
"circular",
"circular disc kernel for dilation and erosion",
false);
235 Optionpk<std::string> method_opt(
"f",
"filter",
"filter function (nvalid, 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), sauvola, sobelx (horizontal edge detection), sobely (vertical edge detection), sobelxy (diagonal edge detection NE-SW),sobelyx (diagonal edge detection NW-SE), density, countid, mode (majority voting), only for classes), smoothnodata (smooth nodata values only) values, ismin, ismax, order (rank pixels in order), stdev, mrf, dwt, dwti, dwt_cut, dwt_cut_from, scramble, shift, savgolay, percentile, proportion)");
236 Optionpk<std::string> resample_opt(
"r",
"resampling-method",
"Resampling method for shifting operation (near: nearest neighbour, bilinear: bi-linear interpolation).",
"near");
237 Optionpk<double> dimX_opt(
"dx",
"dx",
"filter kernel size in x, use odd values only", 3);
238 Optionpk<double> dimY_opt(
"dy",
"dy",
"filter kernel size in y, use odd values only", 3);
239 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");
240 Optionpk<std::string> wavelet_type_opt(
"wt",
"wavelet",
"wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered",
"daubechies");
241 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);
242 Optionpk<int> savgolay_nl_opt(
"nl",
"nl",
"Number of leftward (past) data points used in Savitzky-Golay filter)", 2);
243 Optionpk<int> savgolay_nr_opt(
"nr",
"nr",
"Number of rightward (future) data points used in Savitzky-Golay filter)", 2);
244 Optionpk<int> savgolay_ld_opt(
"ld",
"ld",
"order of the derivative desired in Savitzky-Golay filter (e.g., ld=0 for smoothed function)", 0);
245 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);
246 Optionpk<short> class_opt(
"class",
"class",
"class value(s) to use for density, erosion, dilation, openening and closing, thresholding");
247 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);
248 Optionpk<double> nodata_opt(
"nodata",
"nodata",
"nodata value(s) (used for smoothnodata filter)");
249 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");
250 Optionpk<double> tapz_opt(
"tapz",
"tapz",
"taps used for spectral filtering");
251 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");
252 Optionpk<double> fwhm_opt(
"fwhm",
"fwhm",
"list of full width half to apply spectral filtering (-fwhm band1 -fwhm band2 ...)");
253 Optionpk<std::string> srf_opt(
"srf",
"srf",
"list of ASCII files containing spectral response functions (two columns: wavelength response)");
254 Optionpk<double> wavelengthIn_opt(
"win",
"wavelengthIn",
"list of wavelengths in input spectrum (-win band1 -win band2 ...)");
255 Optionpk<double> wavelengthOut_opt(
"wout",
"wavelengthOut",
"list of wavelengths in output spectrum (-wout band1 -wout band2 ...)");
256 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");
257 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",
"");
258 Optionpk<string> oformat_opt(
"of",
"oformat",
"Output image format (see also gdal_translate).",
"GTiff");
259 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid). Use none to omit color table");
260 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
261 Optionpk<short> down_opt(
"d",
"down",
"down sampling factor. Use value 1 for no downsampling). Use value n>1 for downsampling (aggregation)", 1);
262 Optionpk<string> beta_opt(
"beta",
"beta",
"ASCII file with beta for each class transition in Markov Random Field");
268 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
270 resample_opt.setHide(1);
271 option_opt.setHide(1);
272 wavelet_type_opt.setHide(1);
273 family_opt.setHide(1);
274 savgolay_nl_opt.setHide(1);
275 savgolay_nr_opt.setHide(1);
276 savgolay_ld_opt.setHide(1);
277 savgolay_m_opt.setHide(1);
278 class_opt.setHide(1);
279 threshold_opt.setHide(1);
282 padding_opt.setHide(1);
283 wavelengthIn_opt.setHide(1);
284 wavelengthOut_opt.setHide(1);
292 interpolationType_opt.setHide(1);
293 otype_opt.setHide(1);
294 oformat_opt.setHide(1);
295 colorTable_opt.setHide(1);
300 doProcess=input_opt.retrieveOption(argc,argv);
301 output_opt.retrieveOption(argc,argv);
304 method_opt.retrieveOption(argc,argv);
305 srf_opt.retrieveOption(argc,argv);
306 fwhm_opt.retrieveOption(argc,argv);
307 dimX_opt.retrieveOption(argc,argv);
308 dimY_opt.retrieveOption(argc,argv);
309 dimZ_opt.retrieveOption(argc,argv);
310 nodata_opt.retrieveOption(argc,argv);
311 resample_opt.retrieveOption(argc,argv);
312 option_opt.retrieveOption(argc,argv);
313 wavelet_type_opt.retrieveOption(argc,argv);
314 family_opt.retrieveOption(argc,argv);
315 savgolay_nl_opt.retrieveOption(argc,argv);
316 savgolay_nr_opt.retrieveOption(argc,argv);
317 savgolay_ld_opt.retrieveOption(argc,argv);
318 savgolay_m_opt.retrieveOption(argc,argv);
319 class_opt.retrieveOption(argc,argv);
320 threshold_opt.retrieveOption(argc,argv);
321 tap_opt.retrieveOption(argc,argv);
322 tapz_opt.retrieveOption(argc,argv);
323 padding_opt.retrieveOption(argc,argv);
324 wavelengthIn_opt.retrieveOption(argc,argv);
325 wavelengthOut_opt.retrieveOption(argc,argv);
326 down_opt.retrieveOption(argc,argv);
327 beta_opt.retrieveOption(argc,argv);
333 interpolationType_opt.retrieveOption(argc,argv);
334 otype_opt.retrieveOption(argc,argv);
335 oformat_opt.retrieveOption(argc,argv);
336 colorTable_opt.retrieveOption(argc,argv);
337 disc_opt.retrieveOption(argc,argv);
338 verbose_opt.retrieveOption(argc,argv);
340 catch(
string predefinedString){
341 std::cout << predefinedString << std::endl;
346 cout <<
"Usage: pkfilter -i input -o output [-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;
348 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
353 vector<double> angle_opt;
357 if(input_opt.empty()){
358 cerr <<
"Error: no input file selected, use option -i" << endl;
361 if(output_opt.empty()){
362 cerr <<
"Error: no output file selected, use option -o" << endl;
365 input.
open(input_opt[0]);
366 GDALDataType theType=GDT_Unknown;
368 cout <<
"possible output data types: ";
369 for(
int iType = 0; iType < GDT_TypeCount; ++iType){
371 cout <<
" " << GDALGetDataTypeName((GDALDataType)iType);
372 if( GDALGetDataTypeName((GDALDataType)iType) != NULL
373 && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
374 otype_opt[0].c_str()))
375 theType=(GDALDataType) iType;
377 if(theType==GDT_Unknown)
381 std::cout << std::endl <<
"Output pixel type: " << GDALGetDataTypeName(theType) << endl;
384 if(oformat_opt.size())
385 imageType=oformat_opt[0];
387 if(option_opt.findSubstring(
"INTERLEAVE=")==option_opt.end()){
388 string theInterleave=
"INTERLEAVE=";
390 option_opt.push_back(theInterleave);
398 nband=fwhm_opt.size();
399 else if(srf_opt.size())
400 nband=srf_opt.size();
401 else if(tap_opt.size()||tapz_opt.size())
404 if(method_opt.empty()){
405 errorString=
"Error: no filter selected, use option -f";
408 switch(filter2d::Filter2d::getFilterType(method_opt[0])){
409 case(filter2d::dilate):
410 case(filter2d::erode):
411 case(filter2d::close):
412 case(filter2d::open):
413 case(filter2d::smooth):
416 assert(dimZ_opt[0]>1);
420 case(filter2d::dwti):
421 case(filter2d::dwt_cut):
422 case(filter2d::smoothnodata):
426 case(filter2d::savgolay):
429 dimZ_opt.push_back(1);
430 case(filter2d::dwt_cut_from):
434 assert(threshold_opt.size());
437 errorString=
"filter not implemented in spatial domain";
442 assert(class_opt.size()>1);
444 std::cout <<
"opening output image " << output_opt[0] << std::endl;
445 nband=class_opt.size();
446 case(filter2d::ismin):
447 case(filter2d::ismax):
448 case(filter2d::shift):
449 case(filter2d::scramble):
450 case(filter2d::mode):
451 case(filter2d::sobelx):
452 case(filter2d::sobely):
453 case(filter2d::sobelxy):
454 case(filter2d::countid):
455 case(filter2d::order):
456 case(filter2d::density):
457 case(filter2d::homog):
458 case(filter2d::heterog):
459 case(filter2d::sauvola):
462 errorString=
"filter not implemented in spectral/temporal domain";
476 case(filter2d::mean):
480 case(filter2d::stdev):
481 case(filter2d::nvalid):
482 case(filter2d::median):
483 case(filter2d::percentile):
484 case(filter2d::proportion):
486 if(dimZ_opt.size()==1)
493 errorString=
"filter not implemented";
498 std::cout <<
"opening output image " << output_opt[0] <<
" with " << nband <<
" bands" << std::endl;
499 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);
501 catch(
string errorstring){
502 cerr << errorstring << endl;
512 if(colorTable_opt.size()){
513 if(colorTable_opt[0]!=
"none"){
515 cout <<
"set colortable " << colorTable_opt[0] << endl;
523 if(nodata_opt.size()){
524 for(
int iband=0;iband<output.
nrOfBand();++iband)
531 cout <<
"Set padding to " << padding_opt[0] << endl;
532 filter1d.setPadding(padding_opt[0]);
533 if(class_opt.size()){
535 std::cout<<
"class values: ";
536 for(
int iclass=0;iclass<class_opt.size();++iclass){
538 filter2d.pushClass(class_opt[iclass]);
540 filter1d.pushClass(class_opt[iclass]);
542 std::cout<< class_opt[iclass] <<
" ";
545 std::cout<< std::endl;
548 if(nodata_opt.size()){
550 std::cout<<
"mask values: ";
551 for(
int imask=0;imask<nodata_opt.size();++imask){
553 std::cout<< nodata_opt[imask] <<
" ";
554 filter1d.pushNoDataValue(nodata_opt[imask]);
555 filter2d.pushNoDataValue(nodata_opt[imask]);
558 std::cout<< std::endl;
560 filter1d.setThresholds(threshold_opt);
561 filter2d.setThresholds(threshold_opt);
564 ifstream tapfile(tap_opt[0].c_str());
568 for(
int j=0;j<dimY_opt[0];++j){
569 for(
int i=0;i<dimX_opt[0];++i){
570 tapfile >> taps[j][i];
574 std::cout <<
"taps: ";
575 for(
int j=0;j<dimY_opt[0];++j){
576 for(
int i=0;i<dimX_opt[0];++i){
577 std::cout<< taps[j][i] <<
" ";
579 std::cout<< std::endl;
582 filter2d.setTaps(taps);
584 filter2d.filter(input,output);
586 catch(
string errorstring){
587 cerr << errorstring << endl;
591 else if(tapz_opt.size()){
593 std::cout <<
"taps: ";
594 for(
int itap=0;itap<tapz_opt.size();++itap)
595 std::cout<< tapz_opt[itap] <<
" ";
596 std::cout<< std::endl;
598 filter1d.setTaps(tapz_opt);
599 filter1d.filter(input,output);
601 else if(fwhm_opt.size()){
603 std::cout <<
"spectral filtering to " << fwhm_opt.size() <<
" bands with provided fwhm " << std::endl;
604 assert(wavelengthOut_opt.size()==fwhm_opt.size());
605 assert(wavelengthIn_opt.size());
609 const char* pszMessage;
610 void* pProgressArg=NULL;
611 GDALProgressFunc pfnProgress=GDALTermProgress;
613 pfnProgress(progress,pszMessage,pProgressArg);
614 for(
int y=0;y<input.
nrOfRow();++y){
615 if((y+1+down_opt[0]/2)%down_opt[0])
617 for(
int iband=0;iband<input.
nrOfBand();++iband)
618 input.
readData(lineInput[iband],y,iband);
619 filter1d.applyFwhm<
double>(wavelengthIn_opt,lineInput,wavelengthOut_opt,fwhm_opt, interpolationType_opt[0], lineOutput, down_opt[0], verbose_opt[0]);
620 for(
int iband=0;iband<output.
nrOfBand();++iband){
622 output.
writeData(lineOutput[iband],y/down_opt[0],iband);
624 catch(
string errorstring){
625 cerr << errorstring <<
"in band " << iband <<
", line " << y << endl;
628 progress=(1.0+y)/output.
nrOfRow();
629 pfnProgress(progress,pszMessage,pProgressArg);
632 else if(srf_opt.size()){
634 std::cout <<
"spectral filtering to " << srf_opt.size() <<
" bands with provided SRF " << std::endl;
635 assert(wavelengthIn_opt.size());
636 vector< Vector2d<double> > srf(srf_opt.size());
638 for(
int isrf=0;isrf<srf_opt.size();++isrf){
640 srfFile.open(srf_opt[isrf].c_str());
643 srf[isrf][0].push_back(0);
644 srf[isrf][1].push_back(0);
645 srf[isrf][0].push_back(1);
646 srf[isrf][1].push_back(0);
648 srf[isrf][0].push_back(v);
650 srf[isrf][1].push_back(v);
654 srf[isrf][0].push_back(srf[isrf][0].back()+1);
655 srf[isrf][1].push_back(0);
656 srf[isrf][0].push_back(srf[isrf][0].back()+1);
657 srf[isrf][1].push_back(0);
659 cout <<
"srf file details: " << srf[isrf][0].size() <<
" wavelengths defined" << endl;
661 assert(output.
nrOfBand()==srf.size());
662 double centreWavelength=0;
664 const char* pszMessage;
665 void* pProgressArg=NULL;
666 GDALProgressFunc pfnProgress=GDALTermProgress;
668 pfnProgress(progress,pszMessage,pProgressArg);
669 for(
int y=0;y<input.
nrOfRow();++y){
670 if((y+1+down_opt[0]/2)%down_opt[0])
672 for(
int iband=0;iband<input.
nrOfBand();++iband)
673 input.
readData(lineInput[iband],y,iband);
674 for(
int isrf=0;isrf<srf.size();++isrf){
675 vector<double> lineOutput(output.
nrOfCol());
678 centreWavelength=filter1d.applySrf<
double>(wavelengthIn_opt,lineInput,srf[isrf], interpolationType_opt[0], lineOutput, delta, normalize);
680 std::cout <<
"centre wavelength srf " << isrf <<
": " << centreWavelength << std::endl;
682 output.
writeData(lineOutput,GDT_Float64,y/down_opt[0],isrf);
684 catch(
string errorstring){
685 cerr << errorstring <<
"in srf " << srf_opt[isrf] <<
", line " << y << endl;
689 progress=(1.0+y)/output.
nrOfRow();
690 pfnProgress(progress,pszMessage,pProgressArg);
695 switch(filter2d::Filter2d::getFilterType(method_opt[0])){
696 case(filter2d::dilate):
698 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
704 std::cout<<
"1-D filtering: dilate" << std::endl;
705 filter1d.morphology(input,output,
"dilate",dimZ_opt[0],verbose_opt[0]);
708 filter2d.morphology(input,output,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
710 catch(
string errorstring){
711 cerr << errorstring << endl;
714 case(filter2d::erode):
716 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
720 if(dimZ_opt.size()>0){
722 std::cout<<
"1-D filtering: dilate" << std::endl;
723 filter1d.morphology(input,output,
"erode",dimZ_opt[0]);
726 filter2d.morphology(input,output,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
729 catch(
string errorstring){
730 cerr << errorstring << endl;
733 case(filter2d::close):{
735 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
743 filter1d.morphology(input,tmpout,
"dilate",dimZ_opt[0]);
746 filter2d.morphology(input,tmpout,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
749 catch(std::string errorString){
750 std::cout<< errorString;
755 tmpin.
open(
"/vsimem/dilation.tif");
758 filter1d.morphology(tmpin,output,
"erode",dimZ_opt[0]);
761 filter2d.morphology(tmpin,output,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
764 catch(
string errorstring){
765 cerr << errorstring << endl;
770 case(filter2d::open):{
772 std::cerr <<
"Error: down option not supported for morphological operator" << std::endl;
779 filter1d.morphology(input,tmpout,
"erode",dimZ_opt[0]);
782 filter2d.morphology(input,tmpout,
"erode",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
785 catch(std::string errorString){
786 std::cout<< errorString;
792 tmpin.
open(
"/vsimem/erosion.tif");
794 filter1d.morphology(tmpin,output,
"dilate",dimZ_opt[0]);
797 filter2d.morphology(tmpin,output,
"dilate",dimX_opt[0],dimY_opt[0],angle_opt,disc_opt[0]);
802 catch(
string errorstring){
803 cerr << errorstring << endl;
807 case(filter2d::homog):{
809 filter2d.doit(input,output,
"homog",dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
811 catch(
string errorstring){
812 cerr << errorstring << endl;
816 case(filter2d::heterog):{
818 filter2d.doit(input,output,
"heterog",dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
820 catch(
string errorstring){
821 cerr << errorstring << endl;
825 case(filter2d::sauvola):{
829 for(
int iband=0;iband<input.
nrOfBand();++iband){
833 filter2d.doit(input,output,
"sauvola",dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
835 catch(
string errorstring){
836 cerr << errorstring << endl;
840 case(filter2d::shift):{
842 std::cerr <<
"Error: down option not supported for shift operator" << std::endl;
849 filter2d.shift(input,output,dimX_opt[0],dimY_opt[0],threshold_opt[0],filter2d::Filter2d::getResampleType(resample_opt[0]));
851 catch(
string errorstring){
852 cerr << errorstring << endl;
878 case(filter2d::mrf):{
880 std::cout <<
"Markov Random Field filtering" << std::endl;
887 vector<int> cols(class_opt.size());
888 for(
int iclass=0;iclass<class_opt.size();++iclass)
890 betaReader.readData(beta,cols);
892 std::cout <<
"using values for beta:" << std::endl;
893 for(
int iclass1=0;iclass1<class_opt.size();++iclass1)
894 std::cout <<
" " << iclass1 <<
" (" << class_opt[iclass1] <<
")";
895 std::cout << std::endl;
896 for(
int iclass1=0;iclass1<class_opt.size();++iclass1){
897 std::cout << iclass1 <<
" (" << class_opt[iclass1] <<
")";
898 for(
int iclass2=0;iclass2<class_opt.size();++iclass2)
899 std::cout <<
" " << beta[iclass2][iclass1] <<
" (" << class_opt[iclass2] <<
")";
900 std::cout << std::endl;
903 filter2d.mrf(input, output, dimX_opt[0], dimY_opt[0], beta,
true, down_opt[0], verbose_opt[0]);
906 filter2d.mrf(input, output, dimX_opt[0], dimY_opt[0], 1,
true, down_opt[0], verbose_opt[0]);
908 catch(
string errorstring){
909 cerr << errorstring << endl;
913 case(filter2d::sobelx):{
915 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
928 filter2d.setTaps(theTaps);
930 filter2d.filter(input,output,
true,
true);
932 catch(
string errorstring){
933 cerr << errorstring << endl;
937 case(filter2d::sobely):{
939 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
952 filter2d.setTaps(theTaps);
954 filter2d.filter(input,output,
true,
true);
956 catch(
string errorstring){
957 cerr << errorstring << endl;
961 case(filter2d::sobelxy):{
963 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
976 filter2d.setTaps(theTaps);
978 filter2d.filter(input,output,
true,
true);
980 catch(
string errorstring){
981 cerr << errorstring << endl;
985 case(filter2d::sobelyx):{
987 std::cerr <<
"Error: down option not supported for sobel edge detection" << std::endl;
1000 filter2d.setTaps(theTaps);
1002 filter2d.filter(input,output,
true,
true);
1004 catch(
string errorstring){
1005 cerr << errorstring << endl;
1009 case(filter2d::smooth):{
1011 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1015 if(dimZ_opt.size()){
1017 std::cout<<
"1-D filtering: smooth" << std::endl;
1018 filter1d.smooth(input,output,dimZ_opt[0]);
1021 filter2d.smooth(input,output,dimX_opt[0],dimY_opt[0]);
1024 catch(
string errorstring){
1025 cerr << errorstring << endl;
1029 case(filter2d::smoothnodata):{
1031 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1035 if(dimZ_opt.size()){
1037 std::cout<<
"1-D filtering: smooth" << std::endl;
1038 filter1d.smoothNoData(input,interpolationType_opt[0],output);
1042 std::cout<<
"2-D filtering: smooth" << std::endl;
1043 filter2d.smoothNoData(input,output,dimX_opt[0],dimY_opt[0]);
1046 catch(
string errorstring){
1047 cerr << errorstring << endl;
1051 case(filter2d::dwt):
1053 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1057 if(dimZ_opt.size()){
1059 std::cout<<
"DWT in spectral domain" << std::endl;
1060 filter1d.dwtForward(input, output, wavelet_type_opt[0], family_opt[0]);
1063 filter2d.dwtForward(input, output, wavelet_type_opt[0], family_opt[0]);
1065 catch(
string errorstring){
1066 cerr << errorstring << endl;
1069 case(filter2d::dwti):
1071 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1075 if(dimZ_opt.size()){
1077 std::cout<<
"inverse DWT in spectral domain" << std::endl;
1078 filter1d.dwtInverse(input, output, wavelet_type_opt[0], family_opt[0]);
1081 filter2d.dwtInverse(input, output, wavelet_type_opt[0], family_opt[0]);
1083 catch(
string errorstring){
1084 cerr << errorstring << endl;
1087 case(filter2d::dwt_cut):
1089 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1092 if(dimZ_opt.size()){
1094 std::cout<<
"DWT approximation in spectral domain" << std::endl;
1095 filter1d.dwtCut(input, output, wavelet_type_opt[0], family_opt[0], threshold_opt[0]);
1098 filter2d.dwtCut(input, output, wavelet_type_opt[0], family_opt[0], threshold_opt[0]);
1100 case(filter2d::dwt_cut_from):
1102 std::cerr <<
"Error: down option not supported for this filter" << std::endl;
1106 if(dimZ_opt.size()){
1108 std::cout<<
"DWT approximation in spectral domain" << std::endl;
1109 filter1d.dwtCutFrom(input, output, wavelet_type_opt[0], family_opt[0], static_cast<int>(threshold_opt[0]));
1112 string errorString=
"Error: this filter is not supported in 2D";
1116 catch(
string errorstring){
1117 cerr << errorstring << endl;
1120 case(filter2d::savgolay):{
1121 assert(savgolay_nl_opt.size());
1122 assert(savgolay_nr_opt.size());
1123 assert(savgolay_ld_opt.size());
1124 assert(savgolay_m_opt.size());
1126 std::cout <<
"Calculating Savitzky-Golay coefficients: " << endl;
1127 filter1d.getSavGolayCoefficients(tapz_opt, input.
nrOfBand(), savgolay_nl_opt[0], savgolay_nr_opt[0], savgolay_ld_opt[0], savgolay_m_opt[0]);
1129 std::cout <<
"taps (size is " << tapz_opt.size() <<
"): ";
1130 for(
int itap=0;itap<tapz_opt.size();++itap)
1131 std::cout<< tapz_opt[itap] <<
" ";
1132 std::cout<< std::endl;
1134 filter1d.setTaps(tapz_opt);
1135 filter1d.filter(input,output);
1138 case(filter2d::percentile):
1139 case(filter2d::threshold):
1140 assert(threshold_opt.size());
1142 filter1d.setThresholds(threshold_opt);
1144 filter2d.setThresholds(threshold_opt);
1145 case(filter2d::density):
1146 filter2d.setClasses(class_opt);
1148 std::cout <<
"classes set" << std::endl;
1151 if(dimZ_opt.size()){
1153 filter1d.stat(input,output,method_opt[0]);
1155 assert(down_opt[0]==1);
1156 filter1d.filter(input,output,method_opt[0],dimZ_opt[0]);
1160 filter2d.doit(input,output,method_opt[0],dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
1162 catch(
string errorstring){
1163 cerr << errorstring << endl;
void close(void)
Set the memory (in MB) to cache a number of rows in memory.
int nrOfCol(void) const
Get the number of columns of this dataset.
void setColorTable(const std::string &filename, int band=0)
Set the color table using an (ASCII) file with 5 columns (value R G B alpha)
void readData(T &value, int col, int row, int band=0)
Read a single pixel cell value at a specific column and row for a specific band (all indices start co...
int nrOfRow(void) const
Get the number of rows of this dataset.
GDALColorTable * getColorTable(int band=0) const
Get the GDAL color table for this dataset as an instance of the GDALColorTable class.
CPLErr setGeoTransform(double *gt)
Set the geotransform data for this dataset.
std::string getImageType() const
Get the image type (implemented as the driver description)
bool writeData(T &value, int col, int row, int band=0)
Write a single pixel cell value at a specific column and row for a specific band (all indices start c...
void open(const std::string &filename, const ImgReaderGdal &imgSrc, const std::vector< std::string > &options=std::vector< std::string >())
Open an image for writing, copying image attributes from a source image. Image is directly written to...
std::string getProjection(void) const
Get the projection string (deprecated, use getProjectionRef instead)
GDALDataType getDataType(int band=0) const
Get the GDAL datatype for this dataset.
CPLErr setProjection(const std::string &projection)
Set the projection for this dataset in well known text (wkt) format.
void close(void)
Close the image.
void readDataBlock(Vector2d< T > &buffer2d, int minCol, int maxCol, int minRow, int maxRow, int band=0)
Read pixel cell values for a range of columns and rows for a specific band (all indices start countin...
std::string getGeoTransform() const
Get the geotransform data for this dataset as a string.
CPLErr GDALSetNoDataValue(double noDataValue, int band=0)
Set the GDAL (internal) no data value for this data set. Only a single no data value per band is supp...
void open(const std::string &filename, const GDALAccess &readMode=GA_ReadOnly)
Open an image.
int nrOfBand(void) const
Get the number of bands of this dataset.
std::string getInterleave() const
Get the band coding (interleave)