28 #include <DGtal/base/Common.h>
29 #include "DGtal/io/readers/GenericReader.h"
30 #include "DGtal/io/writers/GenericWriter.h"
31 #include "DGtal/images/ImageContainerBySTLVector.h"
32 #include "DGtal/images/ImageSelector.h"
33 #include <DGtal/geometry/volumes/KanungoNoise.h>
34 #include <DGtal/images/IntervalForegroundPredicate.h>
44 using namespace DGtal;
85 void missingParam ( std::string param )
87 trace.error() <<
" Parameter: "<<param<<
" is required..";
88 trace.info() <<std::endl;
92 typedef ImageSelector < Z2i::Domain, unsigned char>::Type MyImage;
95 int main(
int argc,
char** argv )
99 std::string inputFileName;
100 std::string outputFileName {
"result.png"};
103 app.description(
"Add Kanungo noise to a binary object with 0 values as background points and values >0 for the foreground ones.\n Example: \n imgAddNoise ${DGtal}/examples/samples/klokan.pgm noise.pgm ");
104 app.add_option(
"-i,--input,1", inputFileName,
"input image file name (any 2D image format accepted by DGtal::GenericReader)." )
106 ->check(CLI::ExistingFile);
107 app.add_option(
"-o,--output,2", outputFileName,
"output image file name (any 2D image format accepted by DGtal::GenericWriter)",
true);
108 app.add_option(
"-n,--noise", noise,
"Kanungo noise level in ]0,1[ (default 0.5)",
true);
110 app.get_formatter()->column_width(40);
111 CLI11_PARSE(app, argc, argv);
115 typedef functors::IntervalForegroundPredicate<MyImage> Binarizer;
116 MyImage image = GenericReader<MyImage>::import( inputFileName );
117 trace.info() <<
"Input image: "<< image<<std::endl;
118 Binarizer predicate(image, 0,255);
120 KanungoNoise<Binarizer, Z2i::Domain> kanungo(predicate, image.domain(), noise);
122 MyImage result(image.domain());
123 for(Z2i::Domain::ConstIterator it = image.domain().begin(), itend = image.domain().end(); it!= itend; ++it)
126 result.setValue(*it, 255);
128 result .setValue(*it, 0);
131 result >> outputFileName;