예제 #1
0
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);
  }
}
예제 #2
0
void FuzzyUtils::getFuzzyIntegralSugeno(IplImage* H, IplImage* Delta, int n, float *MeasureG, IplImage* OutputImage)
{
  // MeasureG : est un vecteur contenant 3 mesure g (g1,g2,g3) tel que : g1+g2+g3=1
  // n : =2 cad aggreger les 2 images "H" et "Delta" 
  //	   =1 cad aggreger uniquement les valeurs des composantes couleurs de l'image "Delta"

  PixelUtils p;

  float* HTexturePixel = (float*) malloc(1*sizeof(float));   
  float* DeltaOhtaPixel = (float*) malloc(3*(sizeof(float)));
  int *Indice = (int*) malloc(3*(sizeof(int)));
  float *HI = (float*) malloc(3*(sizeof(float)));
  float *Integral = (float*) malloc(3*(sizeof(float)));
  float* X = (float*) malloc(1*sizeof(float));
  float* XiXj = (float*) malloc(1*sizeof(float));
  float IntegralFlou;

  *Indice = 0;
  *(Indice+1) = 1;
  *(Indice+2) = 2;
  *X = 1.0;

  for(int i = 0; i < H->width; i++)
  {
    for(int j = 0; j < H->height; j++)
    {	
      p.GetGrayPixel(H,i,j,HTexturePixel);
      p.GetPixel(Delta,i,j,DeltaOhtaPixel);

      *(HI+0) = *(HTexturePixel+0);
      *(HI+1) = *(DeltaOhtaPixel+0);
      *(HI+2) = *(DeltaOhtaPixel+1);

      Trier(HI,3,Indice);

      *XiXj = *(MeasureG + (*(Indice+1))) + (*(MeasureG + (*(Indice+2))));			

      *(Integral+0) = min((HI + (*(Indice+0))), X);
      *(Integral+1) = min((HI + (*(Indice+1))), XiXj);
      *(Integral+2) = min((HI + (*(Indice+2))), ((MeasureG+(*(Indice+2)))));

      IntegralFlou = max(Integral,3);
      p.PutGrayPixel(OutputImage,i,j,IntegralFlou);
    }
  }

  free(HTexturePixel);
  free(DeltaOhtaPixel);
  free(Indice);
  free(HI);
  free(X);
  free(XiXj);
  free(Integral);
}
예제 #3
0
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);
}