diff --git a/app/Operations/MICD.cpp b/app/Operations/MICD.cpp index d04ee25ea5cccf0c405857a6a80560077fef5aef..ab62a7637526caee6f3f4552dca7f40694572c5f 100644 --- a/app/Operations/MICD.cpp +++ b/app/Operations/MICD.cpp @@ -28,14 +28,14 @@ MICD::MICD() { long counter; for( counter=0; counter< 128; counter++ ) { - iloiqu[counter] = 0; + iloiqu[counter] = 0; } for( counter=0; counter< 2048*20; counter++ ) { - ((int*)itcod)[counter] = 0; + ((int*)itcod)[counter] = 0; ((int*)itrco)[counter] = 0; } for( counter=0; counter< 40; counter++ ) { - ((int*)ktab)[counter] = 0; + ((int*)ktab)[counter] = 0; } quantdef = NULL; } @@ -83,67 +83,67 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image /* codage de l'image */ for(i=1; i<nbl ; i++) { - for(j=1; j<nbc ; j++) - { - if(rep == PX_EQ_A) { - temp_p = reconstructed_image->getPixelAt( j - 1, i ); - pred = temp_p; - } - else if(rep == PX_EQ_B) { - temp_p = reconstructed_image->getPixelAt( j, i - 1); - pred = temp_p; - } - else if(rep == PX_EQ_APC) { - temp_p = reconstructed_image->getPixelAt( j - 1, i ); - pred = (int)temp_p; - temp_p = reconstructed_image->getPixelAt( j, i - 1 ); - pred = ( pred + (int)temp_p ) / 2; - } - else if(rep == PX_EQ_Q) { + for(j=1; j<nbc ; j++) + { + if(rep == PX_EQ_A) { + temp_p = reconstructed_image->getPixelAt( j - 1, i ); + pred = temp_p; + } + else if(rep == PX_EQ_B) { + temp_p = reconstructed_image->getPixelAt( j, i - 1); + pred = temp_p; + } + else if(rep == PX_EQ_APC) { + temp_p = reconstructed_image->getPixelAt( j - 1, i ); + pred = (int)temp_p; + temp_p = reconstructed_image->getPixelAt( j, i - 1 ); + pred = ( pred + (int)temp_p ) / 2; + } + else if(rep == PX_EQ_Q) { /* - Modified Graham's Algorithm: - if |B-C| - Q <= |B-A| <= |B-C| + Q + Modified Graham's Algorithm: + if |B-C| - Q <= |B-A| <= |B-C| + Q P(X) = (A+C)/2 - else + else if |B-A| > |B-C| P(X) = A else P(X) = C - */ - float A = im->getPixelAt( j - 1, i ); - float B = im->getPixelAt( j - 1, i - 1 ); - float C = im->getPixelAt( j, i - 1 ); - if( ((fabs(B-C) - Q) <= fabs(B-A)) && - (fabs(B-A) <= (fabs(B-C) + Q)) ) { - pred = (uint8_t)((A + C) / 2); - } - else { - if( fabs(B-A) > fabs(B-C) ) { - pred = (uint8_t)A; - } - else { - pred = (uint8_t)C; - } - } - } + */ + float A = im->getPixelAt( j - 1, i ); + float B = im->getPixelAt( j - 1, i - 1 ); + float C = im->getPixelAt( j, i - 1 ); + if( ((fabs(B-C) - Q) <= fabs(B-A)) && + (fabs(B-A) <= (fabs(B-C) + Q)) ) { + pred = (uint8_t)((A + C) / 2); + } + else { + if( fabs(B-A) > fabs(B-C) ) { + pred = (uint8_t)A; + } + else { + pred = (uint8_t)C; + } + } + } - temp_p = reconstructed_image->getPixelAt( j, i ); - ier = (int)temp_p - pred; - codec(0,ier,&icode,&ireco); - pi[ier+255]++; /* proba associe l'erreur de prdiction */ - nbpt++; + temp_p = reconstructed_image->getPixelAt( j, i ); + ier = (int)temp_p - pred; + codec(0,ier,&icode,&ireco); + pi[ier+255]++; /* proba associe l'erreur de prdiction */ + nbpt++; - int tempvalue; - tempvalue = ier + 128; - po = tempvalue; - error_prediction_image->setPixelAt( j, i, po ); - tempvalue = pred + ireco; - if( tempvalue > 255 ) tempvalue = 255; - if( tempvalue < 0 ) tempvalue = 0; - po = tempvalue; - reconstructed_image->setPixelAt( j, i, po ); - } - } + int tempvalue; + tempvalue = ier + 128; + po = tempvalue; + error_prediction_image->setPixelAt( j, i, po ); + tempvalue = pred + ireco; + 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 */ for(i=0 ; i<512 ; i++) @@ -160,7 +160,6 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image returnval = returnval + "\n"; returnval = returnval + print_iloiqu(); - /* libration de la mmoire alloue */ *err_image = error_prediction_image; *recons_image = reconstructed_image; @@ -168,7 +167,7 @@ string MICD::execute( const GrayscaleImage *im, Prediction prediction_alg, image } void MICD::codlq(int m) { - int n,nar,nk,i,j; + int n,nar,nk,i,j; n=iloiqu[0]; ktab[0][m]=iloiqu[1]; @@ -176,10 +175,10 @@ void MICD::codlq(int m) { j= -1; for(i=0;i < n-1 ; i++) { - nk=1+nar-iloiqu[2*i+1]; - do{j++;itcod[j][m]=i;nk++;} while(nk <= 0); - nar=iloiqu[2*i+1]; - itrco[i][m]=iloiqu[2*i+2]; + nk=1+nar-iloiqu[2*i+1]; + do{j++;itcod[j][m]=i;nk++;} while(nk <= 0); + nar=iloiqu[2*i+1]; + itrco[i][m]=iloiqu[2*i+2]; } itcod[j+1][m]=i; itrco[i][m]=iloiqu[2*i+2]; @@ -187,31 +186,31 @@ void MICD::codlq(int m) { } void MICD::codec(int nlq,int ier,int *icode,int *ireco) { - int m,ip,iep,ierp,n,l; + int m,ip,iep,ierp,n,l; m=nlq; ip=ktab[0][m]; ierp=ier-ip; if(ierp > 0) { - ip=ktab[1][m]; - iep=ier-ip; - if(iep < 0) - n=ier - ktab[0][m]; - else - n=ktab[1][m] - ktab[0][m]; - *icode=itcod[n][m]; - l= *icode; - *ireco=itrco[l][m]; + ip=ktab[1][m]; + iep=ier-ip; + if(iep < 0) + n=ier - ktab[0][m]; + else + n=ktab[1][m] - ktab[0][m]; + *icode=itcod[n][m]; + l = *icode; + *ireco=itrco[l][m]; } else { - *icode=itcod[0][m]; - *ireco=itrco[0][m]; + *icode=itcod[0][m]; + *ireco=itrco[0][m]; } } void MICD::set_levels() { - // Fills in iloiqu with the specified values + // Fills in iloiqu with the specified values if( quantdef->size - 1 > 32 || quantdef->size - 1 < 1 ) { char buffer[255]; sprintf( buffer, "Error in MICD::set_levels:\nquantdef->GetNumThresholds() = %d", quantdef->size - 1 ); @@ -228,13 +227,13 @@ void MICD::set_levels() { } string MICD::print_iloiqu() { - string returnval; + string returnval; returnval = "seuils de dcision --------------- niveaux de reconstruction\n"; - int counter; + int counter; char buffer[100]; for( counter=1; counter<= iloiqu[0]*2-1; counter++ ) { if( !(counter & 1 == 1) ) { - sprintf( buffer, " %3d \n", iloiqu[counter] ); + sprintf( buffer, " %3d \n", iloiqu[counter] ); returnval = returnval + buffer; sprintf( buffer, " %3d ---------------------------------------------\n", iloiqu[counter-1] ); returnval = returnval + buffer;