25 #include <Base/Image/Image.hh>
26 #include <Filter/Mean.hh>
27 #include <Filter/Gauss.hh>
28 #include <Filter/Median.hh>
29 #include <Filter/Rescale.hh>
30 #include <Base/Image/ImageIO.hh>
31 #include <Utils/Param.hh>
32 #include <Utils/IOUtils.hh>
48 enum filtertype {none, mean, median, gauss, rescale};
53 cout <<
"Usage: biasfilter [options] infile outfile"<<endl
55 <<
"-r radius : size of the filter kernel: size = 2 * radius + 1"<<endl
56 <<
"-a : use mean filter"<<endl
57 <<
"-g : use gauss filter"<<endl
58 <<
"-b : use median filter"<<endl
59 <<
"-s : scale image, give factor with ="<<endl
61 <<
"-v : verbose"<<endl
62 <<
"-t thresh : median: ignore x<=thresh"<<endl;
65 int main(
int argc,
char *argv[])
89 enums.push_back(
"None"); ids.push_back(none);
90 enums.push_back(
"Mean"); ids.push_back(mean);
91 enums.push_back(
"Median"); ids.push_back(median);
92 enums.push_back(
"Gauss"); ids.push_back(gauss);
93 enums.push_back(
"Rescale");ids.push_back(rescale);
94 int *filter = param.
AddParamEnum(
"FilterType",
"The filter to apply",enums,0,&ids,
'f');
95 int *rad = param.
AddParamInt(
"Radius",
"Radius of image filter", 3,1,1000,
'r');
96 int *threshold = param.
AddParamInt(
"Threshold",
"threshold for image filter", 0,1,100000000,
't');
97 int *factor = param.
AddParamInt(
"Factor",
"Rescale factor", 0,1,100000000,
's');
98 bool *verbose = param.
AddParamBool(
"Verbose",
"Verbose output",
false,
'v');
99 string *input = param.
AddParamString(
"Input",
"Input image to filter",
"",
'i');
100 string *output = param.
AddParamString(
"Output",
"Output image for result",
"out.mip",
'o');
102 if (!IOUtils::ParseCommandLineEvalHelp(param, argc, argv))
105 filtertype UseFilter = (filtertype)(*filter);
106 if (UseFilter == none ) {
107 cout <<
"==> No filtertype specified."<<endl;
124 case median: cout<<
"Median filter "<<endl;
126 case mean: cout<<
"Mean filter"<<endl;
128 case gauss: cout<<
"Gauss filter"<<endl;
130 case rescale: cout<<
"Rescale filter with factor: "<<rescale<<endl;
134 cout <<
" size "<<2*(*rad)+1<<
"x"<<2*(*rad)+1<<endl;
135 if (*threshold > -FLT_MAX) cout <<
" threshold "<<*threshold<<endl;
139 if (ImageIO::Load(*input,inimage)<0){
140 BIASERR(
"Could not load input image:"<<*input);
149 MedianFilterUC.
Filter(img1, img2);
155 meanfilterUC.
Filter(img1,img2);
158 gaussfilterUC.
Filter(img1,img2);
161 rescalefilterUC.
Filter(img1,img2);
164 cout <<
"==> No filtertype specified."<<endl;
169 ImageIO::Save(*output,img2);
176 MedianFilterFLT.
Filter(img1, img2);
179 meanfilterFLT.
Filter(img1,img2);
182 gaussfilterFLT.
Filter(img1,img2);
185 rescalefilterFLT.
Filter(img1,img2);
188 cout <<
"==> No filtertype specified."<<endl;
193 ImageIO::Save(*output,img2);
196 BIASERR(
"Neither a unsigned char nor a float image, returning unfiltered.");
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
averages over a region with constant weights
void SetHalfWinSize(const int hws, bool AdjustSigma=true)
define the half win size of the kernel, if AdjustSigma is true sigma is computed according to the cut...
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
virtual parent class for API definition of all (future) filters
void SetSize(const int size)
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
scales the src to dst using the downsampling factor from SetFactor()
void SetBorderHandling(const int bh)
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
sets gauss kernel if params changed and calls convolution or fast grey implementation if possible ...
This class Param provides generic support for parameters.
enum EStorageType GetStorageType() const
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
This is the base class for images in BIAS.
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
void SetFactor(double factor)
the downsampling factor