30 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include <DGtal/io/readers/GenericReader.h>
34 #include <DGtal/io/writers/GenericWriter.h>
37 #include <DGtal/images/Image.h>
38 #include <DGtal/images/ImageContainerBySTLVector.h>
39 #include <DGtal/images/imagesSetsUtils/SetFromImage.h>
40 #include <DGtal/io/writers/PPMWriter.h>
41 #include <DGtal/math/Statistic.h>
42 #include "DGtal/io/colormaps/GradientColorMap.h"
43 #include <DGtal/math/Statistic.h>
45 #include <boost/program_options/options_description.hpp>
46 #include <boost/program_options/parsers.hpp>
47 #include <boost/program_options/variables_map.hpp>
50 using namespace DGtal;
57 namespace po = boost::program_options;
110 for(
auto const &point: imageA.
domain())
112 unsigned int error =
abs((imageA(point)-imageB(point)));
113 stat.addValue(error);
129 it!=imageA.
domain().end(); it++)
131 int error = (imageA(*it)-imageB(*it))*(imageA(*it)-imageB(*it));
132 stat.addValue(error);
144 template<
typename StatisticT>
146 displayStats(
const StatisticT &aStat,
const string &type)
148 std::cout <<
"# Stats on " << type <<
": mean max min unbiased_variance nb_samples " << std::endl;
149 std::cout << aStat.mean() <<
" " << aStat.max() <<
" " << aStat.min() <<
" "
150 <<
" " << aStat.unbiasedVariance() <<
" " << aStat.samples() << std::endl;
154 int main(
int argc,
char** argv )
157 po::options_description general_opt(
"Allowed options are");
158 general_opt.add_options()
159 (
"help,h",
"display this message")
160 (
"imageA,a", po::value<std::string >(),
"Input filename of image A." )
161 (
"imageB,b", po::value<std::string >(),
"Input filename of image B." )
162 (
"imageError,e", po::value<std::string >(),
"Output error image basename (will generate two images <basename>MSE.ppm and <basename>MAE.ppm)." )
163 (
"setMaxColorValueMSE,S", po::value<int>(),
"Set the maximal color value for the scale display of MSE (else the scale is set the maximal MSE value)." )
164 (
"setMaxColorValueMAE,A", po::value<int>(),
"Set the maximal color value for the scale display of MAE (else the scale is set from the maximal MAE value).");
168 po::variables_map vm;
171 po::store(po::parse_command_line(argc, argv, general_opt), vm);
173 catch(
const std::exception& ex)
176 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
182 if( !parseOK || vm.count(
"help")|| argc<=1 || !vm.count(
"imageA")
183 || !vm.count(
"imageB") )
185 std::cout <<
"Usage: " << argv[0] <<
" --imageA <imageA>.pgm --imageB <imageB>.pgm -imageError <name> \n"
186 <<
"Compare images and displays differences (squared and absolute differences). \n"
187 << general_opt <<
"\n"
188 <<
"Typical use example:\n \t 2dCompImage -a imageA.pgm -b imageB.pgm -e errorImage -S 100 \n";
191 if(!vm.count(
"imageA") || !vm.count(
"imageB"))
193 trace.
error() <<
" The two images filename are needed to be defined" << endl;
199 string inputFileNameA = vm[
"imageA"].as<
string>();
200 string inputFileNameB = vm[
"imageB"].as<
string>();
201 string basenameOutput =vm[
"imageError"].as<
string>();
215 int maxVal = statMA.max();
216 if(vm.count(
"setMaxColorValueMAE"))
218 maxVal = vm[
"setMaxColorValueMAE"].as<
int>();
221 displayStats(statMA,
"Absolute errror");
222 stringstream maeName; maeName << basenameOutput;
223 maeName <<
"MAE.ppm";
229 maxVal = statMA.max();
230 if(vm.count(
"fixMaxColorValueMSE"))
232 maxVal = vm[
"fixMaxColorValueMSE"].as<
int>();
235 displayStats(statSE,
"Squared errror");
236 stringstream mseName; mseName << basenameOutput;
237 mseName <<
"MSE.ppm";
Trace trace(traceWriterTerm)
const Domain & domain() const
std::vector< Value >::const_iterator ConstIterator
void setValue(const Point &aPoint, const Value &aValue)