Skip to content
Snippets Groups Projects
Commit 2ef4cf16 authored by Antoine Lorence's avatar Antoine Lorence
Browse files

[MICD] Improvements on algo

Rename some variables
Remove unnecessary variables
Add missing letters in comments / strings
Add comments
parent 29bf82ec
No related branches found
No related tags found
No related merge requests found
...@@ -51,55 +51,53 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image ...@@ -51,55 +51,53 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image
throw "Error in MICD::execute:\nquantdef = NULL"; throw "Error in MICD::execute:\nquantdef = NULL";
} }
string returnval; string returnval;
int nbl,nbc,size,rep,i,j,pred,ier,ireco,icode; int imgHeight,imgWidth,pred,ier,ireco,icode;
float pi[512],nbpt = 0; float pi[512],nbpt = 0;
double h = 0.; double h = 0.;
rep = prediction_alg;
nbl = im->getHeight(); imgHeight = im->getHeight();
nbc = im->getWidth(); imgWidth = im->getWidth();
size = nbc * nbl;
int po;
int temp_p;
/* initialisation de la loi de quantification */ /* initialisation de la loi de quantification */
set_levels(); set_levels();
codlq(0); codlq(0);
/* allocation mmoire pour l'image d'erreur de prdiction */ /* allocation mmoire pour l'image d'erreur de prdiction */
ImageDouble *error_prediction_image = new ImageDouble(nbc, nbl, 1); ImageDouble *error_prediction_image = new ImageDouble(imgWidth, imgHeight, 1);
Image *reconstructed_image = new GrayscaleImage(*im); Image *reconstructed_image = new GrayscaleImage(*im);
// File these images with all values of zero
long wcounter, hcounter; // Init the error image with 0 values
for( hcounter=0; hcounter< nbl; hcounter++ ) { for(int i=0; i < imgHeight; i++) {
for( wcounter=0; wcounter< nbc; wcounter++ ) { for(int j=0; j< imgWidth; j++) {
error_prediction_image->setPixelAt(wcounter, hcounter, 0); error_prediction_image->setPixelAt(j, i, 0);
} }
} }
/* mise 0 du tableau des probas servant pour le calcul de /* mise a 0 du tableau des probas servant pour le calcul de
l'entropie de l'erreur de prdiction */ l'entropie de l'erreur de prdiction */
for(i=0 ; i<512 ; i++) pi[i]= 0.; for(int i=0 ; i<512 ; i++) pi[i]= 0.;
/* codage de l'image */ /* codage de l'image */
for(i=1; i<nbl ; i++) for(int i=1; i<imgHeight ; i++)
{ {
for(j=1; j<nbc ; j++) for(int j=1; j<imgWidth ; j++)
{ {
if(rep == PX_EQ_A) { switch (prediction_alg) {
temp_p = reconstructed_image->getPixelAt( j - 1, i ); int AplusC;
pred = temp_p; float A,B,C;
}
else if(rep == PX_EQ_B) { case PX_EQ_A:
temp_p = reconstructed_image->getPixelAt( j, i - 1); pred = reconstructed_image->getPixelAt(j-1, i);
pred = temp_p; break;
} case PX_EQ_B:
else if(rep == PX_EQ_APC) { pred = reconstructed_image->getPixelAt(j, i-1);
temp_p = reconstructed_image->getPixelAt( j - 1, i ); break;
pred = (int)temp_p; case PX_EQ_APC:
temp_p = reconstructed_image->getPixelAt( j, i - 1 ); AplusC = reconstructed_image->getPixelAt(j-1, i) + reconstructed_image->getPixelAt(j, i-1);
pred = ( pred + (int)temp_p ) / 2; pred = AplusC / 2;
} break;
else if(rep == PX_EQ_Q) { case PX_EQ_Q:
/* /*
Modified Graham's Algorithm: Modified Graham's Algorithm:
if |B-C| - Q <= |B-A| <= |B-C| + Q if |B-C| - Q <= |B-A| <= |B-C| + Q
...@@ -110,43 +108,43 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image ...@@ -110,43 +108,43 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image
else else
P(X) = C P(X) = C
*/ */
float A = im->getPixelAt( j - 1, i ); A = im->getPixelAt(j-1, i);
float B = im->getPixelAt( j - 1, i - 1 ); B = im->getPixelAt(j-1, i-1);
float C = im->getPixelAt( j, i - 1 ); C = im->getPixelAt(j, i-1);
if( ((fabs(B-C) - Q) <= fabs(B-A)) && if( ((fabs(B-C) - Q) <= fabs(B-A)) &&
(fabs(B-A) <= (fabs(B-C) + Q)) ) { (fabs(B-A) <= (fabs(B-C) + Q)) ) {
pred = (uint8_t)((A + C) / 2); pred = (uint8_t)((A + C) / 2);
} } else {
else {
if( fabs(B-A) > fabs(B-C) ) { if( fabs(B-A) > fabs(B-C) ) {
pred = (uint8_t)A; pred = (uint8_t)A;
} } else {
else {
pred = (uint8_t)C; pred = (uint8_t)C;
} }
} }
break;
default:
break;
} }
temp_p = reconstructed_image->getPixelAt( j, i ); depth_default_t thePixel = reconstructed_image->getPixelAt(j, i);
ier = (int)temp_p - pred; ier = (int) thePixel - pred;
codec(0,ier,&icode,&ireco); codec(0,ier,&icode,&ireco);
pi[ier+255]++; /* proba associe l'erreur de prdiction */
pi[ier+255]++; /* proba associe a l'erreur de prdiction */
nbpt++; nbpt++;
int tempvalue; error_prediction_image->setPixelAt(j, i, ier + 128);
tempvalue = ier + 128;
po = tempvalue; int tempvalue = pred + ireco;
error_prediction_image->setPixelAt( j, i, po ); // Crop the value in [0,255]
tempvalue = pred + ireco; reconstructed_image->setPixelAt(j, i, tempvalue > 255 ? 255 : tempvalue < 0 ? 0 : tempvalue);
if( tempvalue > 255 ) tempvalue = 255;
if( tempvalue < 0 ) tempvalue = 0;
po = tempvalue;
reconstructed_image->setPixelAt( j, i, po );
} }
} }
/* calcul de l'entropie de l'image d'erreur de prdiction */ /* calcul de l'entropie de l'image d'erreur de prediction */
for(i=0 ; i<512 ; i++) for(int i=0 ; i < 512 ; i++)
{ {
if(pi[i] != 0) { if(pi[i] != 0) {
pi[i] /= nbpt; pi[i] /= nbpt;
...@@ -228,7 +226,7 @@ void MICD::set_levels() { ...@@ -228,7 +226,7 @@ void MICD::set_levels() {
string MICD::print_iloiqu() { string MICD::print_iloiqu() {
string returnval; string returnval;
returnval = "seuils de dcision --------------- niveaux de reconstruction\n"; returnval = "seuils de decision --------------- niveaux de reconstruction\n";
int counter; int counter;
char buffer[100]; char buffer[100];
for( counter=1; counter<= iloiqu[0]*2-1; counter++ ) { for( counter=1; counter<= iloiqu[0]*2-1; counter++ ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment