void FuzzyUtils::SimilarityDegreesImage(IplImage* CurrentImage, IplImage* BGImage, IplImage* DeltaImage, int n, int color_space) { PixelUtils p; int i, j; if(n == 1) { float* CurrentGrayPixel = (float*) malloc (1*(sizeof(float))); float* BGGrayPixel = (float*) malloc (1*(sizeof(float))); float* DeltaGrayPixel = (float*) malloc (1*(sizeof(float))); for(i = 0; i < CurrentImage->width; i++) { for(j = 0; j < CurrentImage->height; j++) { p.GetGrayPixel(CurrentImage,i,j,CurrentGrayPixel); p.GetGrayPixel(BGImage,i,j,BGGrayPixel); RatioPixels(CurrentGrayPixel,BGGrayPixel,DeltaGrayPixel,1); p.PutGrayPixel(DeltaImage,i,j,*DeltaGrayPixel); } } free(CurrentGrayPixel); free(BGGrayPixel); free(DeltaGrayPixel); } if(n != 1) { IplImage* ConvertedCurrentImage = cvCreateImage(cvSize(CurrentImage->width, CurrentImage->height), IPL_DEPTH_32F, 3); IplImage* ConvertedBGImage = cvCreateImage(cvSize(CurrentImage->width, CurrentImage->height), IPL_DEPTH_32F, 3); float* ConvertedCurrentPixel = (float*) malloc(3*(sizeof(float))); float* ConvertedBGPixel = (float*) malloc(3*(sizeof(float))); float* DeltaConvertedPixel = (float*) malloc(3*(sizeof(float))); p.ColorConversion(CurrentImage,ConvertedCurrentImage,color_space); p.ColorConversion(BGImage,ConvertedBGImage,color_space); for(i = 0; i < CurrentImage->width; i++) { for(j = 0; j < CurrentImage->height; j++) { p.GetPixel(ConvertedCurrentImage,i,j,ConvertedCurrentPixel); p.GetPixel(ConvertedBGImage,i,j,ConvertedBGPixel); RatioPixels(ConvertedCurrentPixel,ConvertedBGPixel,DeltaConvertedPixel,3); p.PutPixel(DeltaImage,i,j,DeltaConvertedPixel); } } free(ConvertedCurrentPixel); free(ConvertedBGPixel); free(DeltaConvertedPixel); cvReleaseImage(&ConvertedCurrentImage); cvReleaseImage(&ConvertedBGImage); } }
void FuzzyUtils::AdaptativeSelectiveBackgroundModelUpdate(IplImage* CurrentImage, IplImage* BGImage, IplImage* OutputImage, IplImage* Integral, float seuil, float alpha) { PixelUtils p; float beta = 0.0; float* CurentImagePixel = (float*) malloc(3*sizeof(float)); float* BGImagePixel = (float*) malloc(3*sizeof(float)); float* OutputImagePixel = (float*) malloc(3*sizeof(float)); float* IntegralImagePixel = (float*) malloc(1*sizeof(float)); float *Maximum = (float*) malloc(1*sizeof(float)); float *Minimum = (float*) malloc(1*sizeof(float)); p.ForegroundMaximum(Integral, Maximum, 1); p.ForegroundMinimum(Integral, Minimum, 1); for(int i = 0; i < CurrentImage->width; i++) { for(int j = 0; j < CurrentImage->height; j++) { p.GetPixel(CurrentImage, i, j, CurentImagePixel); p.GetPixel(BGImage, i, j, BGImagePixel); p.GetGrayPixel(Integral, i, j, IntegralImagePixel); beta = 1 - ((*IntegralImagePixel) - ((*Minimum / (*Minimum - *Maximum)) * (*IntegralImagePixel) - (*Minimum * (*Maximum) / (*Minimum - *Maximum)))); for(int k = 0; k < 3; k++) *(OutputImagePixel + k) = beta * (*(BGImagePixel + k)) + (1 - beta) * (alpha * (*(CurentImagePixel+k)) + (1-alpha) * (*(BGImagePixel+k))); p.PutPixel(OutputImage, i, j, OutputImagePixel); } } free(CurentImagePixel); free(BGImagePixel); free(OutputImagePixel); free(IntegralImagePixel); free(Maximum); free(Minimum); }