void FuzzyUtils::LBP(IplImage* InputImage, IplImage* LBPimage) { PixelUtils p; float* neighberPixel = (float*) malloc(9*sizeof(float)); float* BinaryValue = (float*) malloc(9*sizeof(float)); float* CarreExp = (float*) malloc(9*sizeof(float)); float* valLBP = (float*) malloc(1*sizeof(float)); *valLBP = 0; int x = 0, y = 0; // on implemente les 8 valeurs puissance de 2 qui correspondent aux 8 elem. d'image voisins au elem. d'image central *(CarreExp+0)=1.0; *(CarreExp+1)=2.0; *(CarreExp+2)=4.0; *(CarreExp+3)=8.0; *(CarreExp+4)=0.0; *(CarreExp+5)=16.0; *(CarreExp+6)=32.0; *(CarreExp+7)=64.0; *(CarreExp+8)=128.0; //le calcule de LBP //pour les 4 coins /* 1.*/ if(x==0 && y==0) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,4,0); *valLBP=*valLBP+((*(BinaryValue+1))*(*(CarreExp+1))+(*(BinaryValue+2))*(*(CarreExp+2))+(*(BinaryValue+3))*(*(CarreExp+3)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } /* 2.*/ if(x==0 && y==InputImage->width) { *valLBP=0; p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,4,1); *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+2))*(*(CarreExp+2))+(*(BinaryValue+3))*(*(CarreExp+3)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } /* 3.*/ if(x==InputImage->height && y==0) { *valLBP=0; p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,4,2); *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+1))*(*(CarreExp+1))+(*(BinaryValue+3))*(*(CarreExp+3)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } /* 4.*/ if(x==InputImage->height && y==InputImage->width) { *valLBP=0; p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,4,3); *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+1))*(*(CarreExp+1))+(*(BinaryValue+2))*(*(CarreExp+2)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } //le calcul de LBP pour la première ligne : L(0) if(x==0 && (y!=0 && y!=InputImage->width)) { for(int y = 1; y < InputImage->width-1; y++) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,6,4); *valLBP=0; *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+1))*(*(CarreExp+1))+(*(BinaryValue+2))*(*(CarreExp+2))+(*(BinaryValue+3))*(*(CarreExp+3))+(*(BinaryValue+5))*(*(CarreExp+5)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } } //le calcul de LBP pour la dernière colonne : C(w) if((x!=0 && x!=InputImage->height) && y==InputImage->width) { for(int x = 1; x < InputImage->height-1; x++) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,6,4); *valLBP=0; *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+1))*(*(CarreExp+1))+(*(BinaryValue+2))*(*(CarreExp+2))+(*(BinaryValue+3))*(*(CarreExp+3))+(*(BinaryValue+5))*(*(CarreExp+5)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } } //le calcul de LBP pour la dernière ligne : L(h) if(x==InputImage->height && (y!=0 && y!=InputImage->width)) { for(int y = 1; y < InputImage->width-1; y++) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,6,1); *valLBP=0; *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp))+(*(BinaryValue+2))*(*(CarreExp+2))+(*(BinaryValue+3))*(*(CarreExp+3))+(*(BinaryValue+4))*(*(CarreExp+4))+(*(BinaryValue+5))*(*(CarreExp+5)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } } //le calcul de LBP pour la première colonne : C(0) if((x!=0 && x!=InputImage->height) && y==0) { for(int x = 1; x <InputImage->height-1; x++) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,6,2); *valLBP=0; *valLBP=*valLBP+((*(BinaryValue))*(*(CarreExp+5))+(*(BinaryValue+1))*(*(CarreExp+6))+(*(BinaryValue+3))*(*(CarreExp+3))+(*(BinaryValue+4))*(*(CarreExp))+(*(BinaryValue+5))*(*(CarreExp+1)))/255.0; p.PutGrayPixel(LBPimage,x,y,*valLBP); } } //pour le reste des elements d'image for(int y = 1; y < InputImage->height-1; y++) { for(int x = 1; x < InputImage->width-1; x++) { p.getNeighberhoodGrayPixel(InputImage, x,y,neighberPixel); getBinValue(neighberPixel,BinaryValue,9,4); //le calcul de la valeur du LBP pour chaque elem. d'im. *valLBP=0; for(int l = 0; l < 9; l++) *valLBP = *valLBP + ((*(BinaryValue+l)) * (*(CarreExp+l))) / 255.0; //printf("\nvalLBP(%d,%d)=%f",x,y,*valLBP); p.PutGrayPixel(LBPimage,x,y,*valLBP); } } free(neighberPixel); free(BinaryValue); free(CarreExp); free(valLBP); }