/**********************************************************************
jlfilter2d_lib.h: program to filter raster images in spatial domain
Author(s): Pieter.Kempeneers@ec.europa.eu
Copyright (C) 2016-2020 European Union (Joint Research Centre)
This file is part of jiplib.
jiplib is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jiplib is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jiplib. If not, see .
***********************************************************************/
#ifndef _JLFILTER2D_LIB_H_
#define _JLFILTER2D_LIB_H_
#include "imageclasses/Jim.h"
#include "apps/AppFactory.h"
//todo: add support for different padding strategies
template void Jim::firfilter2d_t(Jim& imgWriter, app::AppFactory& app){
Optionjl taps_opt("taps", "taps", "taps used for spatial filtering");
Optionjl dimx_opt("dimx", "dimx", "number of taps used for columns");
Optionjl dimy_opt("dimy", "dimy", "number of taps used for rows");
Optionjl nodata_opt("nodata", "nodata", "list of no data values not taken into account");
/* Optionjl padding_opt("pad","pad", "Padding method for filtering (how to handle edge effects). Choose between: symmetric, replicate, circular, zero (pad with 0).", "symmetric"); */
/* Optionjl abs_opt("abs", "abs", "use absolute values when filtering",false); */
Optionjl norm_opt("norm", "norm", "normalize tap values values when filtering",false);
Optionjl verbose_opt("v", "verbose", "verbose mode if > 0", 0,2);
bool doProcess;//stop process when program was invoked with help option (-h --help)
try{
doProcess=taps_opt.retrieveOption(app);
dimx_opt.retrieveOption(app);
dimy_opt.retrieveOption(app);
nodata_opt.retrieveOption(app);
/* abs_opt.retrieveOption(app); */
norm_opt.retrieveOption(app);
/* padding_opt.retrieveOption(app); */
verbose_opt.retrieveOption(app);
if(!doProcess){
std::cout << std::endl;
std::ostringstream helpStream;
helpStream << "short option -h shows basic options only, use long option --help to show all options" << std::endl;
throw(helpStream.str());//help was invoked, stop processing
}
std::vector taps(taps_opt.begin(),taps_opt.end());
if(norm_opt[0]&&nodata_opt.empty()){
if(verbose_opt[0])
std::cout << "normalizing taps" << std::endl;
double norm=0;
for(size_t itap=0;itap(taps[itap]));
}
if(norm){
for(size_t itap=0;itap(getDataPointer(iband));
T* pout=static_cast(imgWriter.getDataPointer(iband));
int indexI=0;
int indexJ=0;
if(nodata_opt.size()){
for(int y=0;y=ncol-(dimX-1)/2)
indexI=x-abs(i);
if(y<(dimY-1)/2)
indexJ=y+abs(j);
else if(y>=nrow-(dimY-1)/2)
indexJ=y-abs(j);
//do not take masked values into account
bool masked=false;
for(int imask=0;imask0)
pout[y*ncol+x]/=norm;
}
}
}
else{
for(int y=0;y=ncol-(dimX-1)/2)
indexI=x-abs(i);
if(y<(dimY-1)/2)
indexJ=y+abs(j);
else if(y>=nrow-(dimY-1)/2)
indexJ=y-abs(j);
pout[y*ncol+x]+=(taps[((dimY-1)/2+j)*dimX+(dimX-1)/2+i]*pin[indexJ*ncol+indexI]);
}
}
}
}
}
}
}
catch(std::string predefinedString){
std::cout << predefinedString << std::endl;
throw;
}
}
#endif // _JLFILTER2D_LIB_H_