DGtalTools  1.2.0
volImageMetrics.cpp
1 
72 #include <iostream>
73 #include <limits>
74 
75 #include <DGtal/base/Common.h>
76 #include <DGtal/io/readers/GenericReader.h>
77 #include <DGtal/io/writers/GenericWriter.h>
78 #include <DGtal/helpers/StdDefs.h>
79 #include <DGtal/images/Image.h>
80 #include <DGtal/images/ImageContainerBySTLVector.h>
81 #include <DGtal/images/imagesSetsUtils/SetFromImage.h>
82 #include <DGtal/math/Statistic.h>
83 
84 #include "CLI11.hpp"
85 
86 using namespace std;
87 using namespace DGtal;
88 using namespace Z3i;
89 
90 typedef ImageContainerBySTLVector < Z3i::Domain, int > Image3D;
91 typedef ImageContainerBySTLVector < Z2i::Domain, int > Image2D;
92 
93 double
94 getRMSE(const Image3D & imageA, const Image3D &imageB){
95  double sumDiff=0;
96  for(Image3D::Domain::ConstIterator it = imageA.domain().begin(); it!=imageA.domain().end(); it++){
97  sumDiff+=(imageA(*it)-imageB(*it))*(imageA(*it)-imageB(*it));
98  }
99  return sqrt(sumDiff/imageA.domain().size());
100 }
101 
102 double
103 getPSNR(const Image3D & imageA, const Image3D &imageB, double rmsd){
104  unsigned long long int d = std::numeric_limits<Image3D::Value>::max();
105  return 10.0*log10(d*d/rmsd);
106 }
107 
108 
109 int main(int argc, char**argv)
110 {
111 
112  // parse command line using CLI ----------------------------------------------
113  CLI::App app;
114  std::string inputFileNameVolA;
115  std::string inputFileNameVolB;
116 
117  app.description("Apply basic image measures (RMSE, PSNR) between two volumetric images A and B. \n Basic usage:\n \t volImageMetrics --volA <volAFilename> --volB <volBFilename> \n Typical use :\n volImageMetrics -a imageA.vol -b imageB.vol \n");
118  app.add_option("-a,--volA,1", inputFileNameVolA, "Input filename of volume A (vol format, and other pgm3d can also be used)." )
119  ->required()
120  ->check(CLI::ExistingFile);
121  app.add_option("-b,--volB,2", inputFileNameVolB, "Input filename of volume B (vol format, and other pgm3d can also be used)." )
122  ->required()
123  ->check(CLI::ExistingFile);
124 
125  app.get_formatter()->column_width(40);
126  CLI11_PARSE(app, argc, argv);
127  // END parse command line using CLI ----------------------------------------------
128 
129  Image3D imageA = GenericReader<Image3D>::import(inputFileNameVolA);
130  Image3D imageB = GenericReader<Image3D>::import(inputFileNameVolB);
131 
132  std::cout << "# Image based measures (generated with volImageMetrics) given with the image A: "<< inputFileNameVolA<< " and the image B: "<< inputFileNameVolB << endl;
133  std::cout << "# RMSE PSNR "<< endl;
134 
135  double rmse= getRMSE(imageA, imageB);
136  double psnr= getPSNR(imageA, imageB, rmse);
137 
138  std::cout << " " << rmse << " " << psnr << endl;
139  return 1;
140 }
Definition: ATu0v1.h:57