From 97f25d8907db7f92f8a7ac786b5b40a774c81e30 Mon Sep 17 00:00:00 2001
From: Antoine Lorence <antoine.lorence@insa-rennes.fr>
Date: Thu, 13 Nov 2014 16:39:14 +0100
Subject: [PATCH] [MICD] Fix values on generated error image: remove clipping

The error is now stored in an Image with double values,
without restriction on these
---
 app/Operations/MICD.cpp           |  7 ++-----
 app/Operations/MICD.h             |  2 +-
 app/Operations/MICDDialog.cpp     |  1 -
 app/Operations/MICDEncodingOp.cpp | 10 ++++++----
 core/Operation.cpp                |  2 +-
 core/Operation.h                  |  2 +-
 6 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/app/Operations/MICD.cpp b/app/Operations/MICD.cpp
index 03232e8..d04ee25 100644
--- a/app/Operations/MICD.cpp
+++ b/app/Operations/MICD.cpp
@@ -45,7 +45,7 @@ MICD::~MICD()
 
 }
 
-string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, Image **err_image, Image **recons_image, double Q ) {
+string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, imagein::ImageDouble **err_image, Image **recons_image, double Q ) {
     char buffer[255];
     if( quantdef == NULL ) {
         throw "Error in MICD::execute:\nquantdef = NULL";
@@ -66,7 +66,7 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, Image
     set_levels();
     codlq(0);
     /* allocation mmoire pour l'image d'erreur de prdiction */
-    GrayscaleImage *error_prediction_image = new GrayscaleImage(nbc, nbl);
+    ImageDouble *error_prediction_image = new ImageDouble(nbc, nbl, 1);
     Image *reconstructed_image = new GrayscaleImage(*im);
     // File these images with all values of zero
     long wcounter, hcounter;
@@ -135,8 +135,6 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, Image
 
          int tempvalue;
          tempvalue = ier + 128;
-         if( tempvalue > 255 ) tempvalue = 255;
-         if( tempvalue < 0 ) tempvalue = 0;
          po = tempvalue;
          error_prediction_image->setPixelAt( j, i, po );
          tempvalue = pred + ireco;
@@ -156,7 +154,6 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, Image
         }
     }
 
-
     /* affichage des rsultats */
     sprintf(buffer, "\nL'entropie de l'image d'erreur de prediction vaut : %lf\n",h);
     returnval = returnval + buffer;
diff --git a/app/Operations/MICD.h b/app/Operations/MICD.h
index c54b9fa..16a1d8a 100644
--- a/app/Operations/MICD.h
+++ b/app/Operations/MICD.h
@@ -30,7 +30,7 @@ public:
     MICD();
     enum Prediction {PX_EQ_A, PX_EQ_B, PX_EQ_APC, PX_EQ_Q};
     virtual ~MICD();
-    std::string execute( const imagein::GrayscaleImage *im, Prediction prediction_alg, imagein::Image **err_image, imagein::Image **recons_image, double Q = 0 );
+    std::string execute(const imagein::GrayscaleImage *im, Prediction prediction_alg, imagein::ImageDouble **err_image, imagein::Image **recons_image, double Q = 0 );
     void setQuantification( Quantification* tquantdef );
 private:
     std::string print_iloiqu();
diff --git a/app/Operations/MICDDialog.cpp b/app/Operations/MICDDialog.cpp
index ca87540..b43c67c 100644
--- a/app/Operations/MICDDialog.cpp
+++ b/app/Operations/MICDDialog.cpp
@@ -55,7 +55,6 @@ Quantification* MICDDialog::getQuantification() const {
     catch(std::exception&) {
         return NULL;
     }
-
 }
 
 MICD::Prediction MICDDialog::getPrediction() const {
diff --git a/app/Operations/MICDEncodingOp.cpp b/app/Operations/MICDEncodingOp.cpp
index 19e5e2f..3f16cf4 100644
--- a/app/Operations/MICDEncodingOp.cpp
+++ b/app/Operations/MICDEncodingOp.cpp
@@ -43,21 +43,23 @@ void MICDEncodingOp::operator()(const imagein::Image* img, const std::map<const
     QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());
 
 
-    if(code!=QDialog::Accepted) return;
+    if(code != QDialog::Accepted) return;
 
     MICD micd;
     try {
         micd.setQuantification(dialog->getQuantification());
     }
     catch(const char* str) {
-        QMessageBox::critical(NULL, qApp->translate("MICD", "Error while loading quantification file"), qApp->translate("MICD", "The specified quantification file could not be opened !"));
+        QMessageBox::critical(NULL, qApp->translate("MICD", "Error while loading quantification file"),
+                              qApp->translate("MICD", "The specified quantification file could not be opened !"));
         return;
     }
     GrayscaleImage* image = Converter<GrayscaleImage>::convert(*img);
-    Image *errorImage, *reconstructedImage;
+    Image *reconstructedImage;
+    ImageDouble *errorImage;
     string s = micd.execute(image, dialog->getPrediction(), &errorImage, &reconstructedImage, dialog->getQ());
     outText(s);
-    outImage(errorImage, qApp->translate("MICD", "Error image").toStdString());
+    outDoubleImage(errorImage, qApp->translate("MICD", "Error image").toStdString());
     outImage(reconstructedImage, qApp->translate("MICD", "Reconstructed image").toStdString());
 }
 
diff --git a/core/Operation.cpp b/core/Operation.cpp
index 1d78a0c..59b8f32 100644
--- a/core/Operation.cpp
+++ b/core/Operation.cpp
@@ -68,7 +68,7 @@ void GenericOperation::outImage(imagein::Image* img, string title) {
     this->outImgWnd(wnd, title);
 }
 
-void GenericOperation::outDoubleImage(imagein::Image_t<double>* img, string title, bool norm, bool log, double logScale, bool abs) {
+void GenericOperation::outDoubleImage(imagein::ImageDouble* img, string title, bool norm, bool log, double logScale, bool abs) {
     DoubleImageWindow* wnd = new DoubleImageWindow(img, QString(), norm, log, logScale, abs);
     this->outImgWnd(wnd, title);
 }
diff --git a/core/Operation.h b/core/Operation.h
index 148a194..73ce809 100644
--- a/core/Operation.h
+++ b/core/Operation.h
@@ -120,7 +120,7 @@ class GenericOperation {
      * @param logScale The logarithm scale constant to apply if the Image is displayed using log. scale (value from 8^-3 to 8^3, see genericinterface::DoubleImageWindow for more details).
      * @param abs wether to display an absolute value version of the Image (doesn't affect the data contained in the image, compatible with any other options).
      */
-    void outDoubleImage(imagein::Image_t<double>* img, std::string title = "", bool norm=false, bool log=false, double logScale = 1., bool abs = false);
+    void outDoubleImage(imagein::ImageDouble* img, std::string title = "", bool norm=false, bool log=false, double logScale = 1., bool abs = false);
 
 
     /**
-- 
GitLab