From 95156633bb0ac1c51d343f5c60d66ddfa57bb3fa Mon Sep 17 00:00:00 2001 From: qbigot <quentin.bigot@insa-rennes.fr> Date: Wed, 5 Jul 2017 09:26:43 +0200 Subject: [PATCH] added error prediction image entropy calculation to DPCM --- app/Operations/DPCM.cpp | 33 +++++++++++++++++++++++---------- app/Operations/Transforms.cpp | 8 +++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/Operations/DPCM.cpp b/app/Operations/DPCM.cpp index 1d692bd..6f35ccc 100644 --- a/app/Operations/DPCM.cpp +++ b/app/Operations/DPCM.cpp @@ -47,15 +47,16 @@ DPCM::~DPCM() } string DPCM::execute( const GrayscaleImage *im, Prediction prediction_alg, imagein::ImageDouble **quant_err_image, imagein::ImageDouble **new_err_image, Image **recons_image, Image **pred_image, double Q ) { - char buffer[255]; + char buffer[255], buffer2[255]; if( quantdef == NULL ) { throw "Error in DPCM::execute:\nquantdef = NULL"; } string returnval; - int imgHeight,imgWidth,pred,ier,ireco,icode; + int imgHeight,imgWidth,pred,ier,ierq,ireco,icode; - float pi[512],nbpt = 0; + float pi[512],piq[512],nbpt = 0; double h = 0.; + double hq = 0.; imgHeight = im->getHeight(); imgWidth = im->getWidth(); @@ -80,7 +81,7 @@ string DPCM::execute( const GrayscaleImage *im, Prediction prediction_alg, image /* mise a 0 du tableau des probas servant pour le calcul de l'entropie de l'erreur de prdiction */ - for(int i=0 ; i<512 ; i++) pi[i]= 0.; + for(int i=0 ; i<512 ; i++) {pi[i]= 0.; piq[i]=0;} /* codage de l'image */ for(int i=1; i<imgHeight ; i++) @@ -140,37 +141,49 @@ string DPCM::execute( const GrayscaleImage *im, Prediction prediction_alg, image prediction_image->setPixelAt(j,i,pred); depth_default_t thePixel = reconstructed_image->getPixelAt(j, i); + //erreur de prediction ier = thePixel - pred; new_error_prediction_image->setPixelAt(j, i, ier); - ier = quantdef->valueOf(ier); + /* proba associe a l'erreur de prediction */ - codec(0, ier, &icode, &ireco); + //quantification erreur de prediction + ierq = quantdef->valueOf(ier); - pi[ier+255]++; /* proba associe a l'erreur de prdiction */ + codec(0, ierq, &icode, &ireco);//(QB) action ? on suppose codage/decodage sans perte : ireco = ierq + + pi[ier+255]++; + piq[ierq+255]++; /* proba associe a l'erreur de prediction */ nbpt++; - //TODO : changer le nom de l'image en quantized_error_prediction_image (done) - quantized_error_prediction_image->setPixelAt(j, i, ier); + quantized_error_prediction_image->setPixelAt(j, i, ierq); + // valeur reconstruite int tempvalue = pred + ireco; // Crop the value in [0,255] reconstructed_image->setPixelAt(j, i, tempvalue > 255 ? 255 : tempvalue < 0 ? 0 : tempvalue); } } - /* calcul de l'entropie de l'image d'erreur de prediction */ + /* calcul de l'entropie de l'image d'erreur de prediction quantifiee */ for(int i=0 ; i < 512 ; i++) { if(pi[i] != 0) { pi[i] /= nbpt; h -= (double)pi[i] * log((double)pi[i])/log((double)2.0); } + if(piq[i] != 0) { + piq[i] /= nbpt; + hq -= (double)piq[i] * log((double)piq[i])/log((double)2.0); + } } /* affichage des rsultats */ sprintf(buffer, "\nL'entropie de l'image d'erreur de prediction vaut : %lf\n",h); + sprintf(buffer2, "\nL'entropie de l'image d'erreur de prediction quantifiee vaut : %lf\n",hq); returnval = returnval + buffer; returnval = returnval + "\n"; + returnval = returnval + buffer2; + returnval = returnval + "\n"; returnval = returnval + print_iloiqu(); /* libration de la mmoire alloue */ diff --git a/app/Operations/Transforms.cpp b/app/Operations/Transforms.cpp index 9eefb95..b2fd26b 100644 --- a/app/Operations/Transforms.cpp +++ b/app/Operations/Transforms.cpp @@ -117,11 +117,13 @@ Image_t<double>* Transforms::hough2(const Image *image, double angleStep, double { if(image->getPixelAt(i, j, c) == 255) { - + //TODO : parcourir entre -180 et 90 for(double te=0; te < 180; te += angleStep) // on parcourt la matrice { - const double coste = cos(te * pi / 180.); - double sinte = sin(te * pi / 180.); + //const double coste = cos(te * pi / 180.); + const double coste = 1; + //double sinte = sin(te * pi / 180.); + double sinte=1 ; // for(double ro = 0; ro < imageDiag; ro += rhoStep) // { -- GitLab