70 #include <DGtal/base/Common.h>
71 #include <DGtal/io/readers/GenericReader.h>
72 #include <DGtal/io/writers/GenericWriter.h>
73 #include <DGtal/helpers/StdDefs.h>
74 #include <DGtal/images/Image.h>
75 #include <DGtal/images/ImageContainerBySTLVector.h>
76 #include <DGtal/images/imagesSetsUtils/SetFromImage.h>
77 #include <DGtal/math/Statistic.h>
79 #include <boost/program_options/options_description.hpp>
80 #include <boost/program_options/parsers.hpp>
81 #include <boost/program_options/variables_map.hpp>
86 using namespace DGtal;
89 namespace po = boost::program_options;
99 sumDiff+=(imageA(*it)-imageB(*it))*(imageA(*it)-imageB(*it));
101 return sqrt(sumDiff/imageA.
domain().size());
106 getPSNR(
const Image3D & imageA,
const Image3D &imageB,
double rmsd){
107 unsigned long long int d = std::numeric_limits<Image3D::Value>::max();
108 return 10.0*log10(d*d/rmsd);
114 int main(
int argc,
char**argv)
117 po::options_description general_opt (
"Allowed options are: " );
118 general_opt.add_options()
119 (
"help,h",
"display this message." )
120 (
"volA,a", po::value<std::string>(),
"Input filename of volume A (vol format, and other pgm3d can also be used)." )
121 (
"volB,b", po::value<std::string>(),
"Input filename of volume B (vol format, and other pgm3d can also be used)." );
124 po::variables_map vm;
126 po::store(po::parse_command_line(argc, argv, general_opt), vm);
127 }
catch(
const std::exception& ex){
129 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
133 if ( !parseOK || vm.count (
"help" ) || ! vm.count(
"volA")||! vm.count(
"volB") )
135 trace.
info() <<
"Apply basic image measures (RMSE, PSNR) between two volumetric images A and B."<<std::endl
136 << std::endl <<
"Basic usage: "<<std::endl
137 <<
"\t volImageMetrics --volA <volAFilename> --volB <volBFilename> "<<std::endl
138 << general_opt <<
"\n"
139 <<
"Typical use :\n volImageMetrics -a imageA.vol -b imageB.vol \n" ;
144 if(! vm.count(
"volA")||! vm.count(
"volB"))
146 trace.
error() <<
" The two volume filename are needed to be defined" << endl;
150 std::string volAFilename = vm[
"volA"].as<std::string>();
151 std::string volBFilename = vm[
"volB"].as<std::string>();
157 std::cout <<
"# Image based measures (generated with volImageMetrics) given with the image A: "<< volAFilename<<
" and the image B: "<< volBFilename << endl;
158 std::cout <<
"# RMSE PSNR "<< endl;
160 double rmse= getRMSE(imageA, imageB);
161 double psnr= getPSNR(imageA, imageB, rmse);
163 std::cout <<
" " << rmse <<
" " << psnr << endl;
Trace trace(traceWriterTerm)
const Domain & domain() const
std::vector< Value >::const_iterator ConstIterator