Beispiel #1
0
void drawSpectrum(int w, int h) {  
  int i;
  float bw, bh;
  float r, g, b;
  
  // draw background
  glColor4f(0.0, 0.0, 0.0,0.5);
  glBegin( GL_QUADS );
  glVertex2i(0, 0);
  glVertex2i(w, 0);
  glVertex2i(w, h);
  glVertex2i(0, h);
  glEnd();
  
  bw=(float)(w-20)/optNumBins;
  for (i=0;i<optNumBins;i++) {
    // draw plot background   
    glColor4f(0.2, 0.2, 0.2,0.5);
    glBegin( GL_QUADS );
    glVertex2i(10+bw*i, h-10);
    glVertex2i(10+bw*(i+1), h-10);
    glVertex2i(10+bw*(i+1), 10);
    glVertex2i(10+bw*i, 10);
    glEnd();
    
    //draw colorbar
    bh=(h-20)/2*getBinValue(i);
    if (bh > h-20) bh=h-20;
    hsv2rgb(5.0-getBinEnergy(i)/optInitEnergy*5.0,1.0,1.0,&r,&g,&b);
    glColor3f(r, g, b);
    glBegin( GL_QUADS );
    glVertex2i(10+bw*i,h-10);
    glVertex2i(10+bw*(i+1),h-10);
    glVertex2i(10+bw*(i+1),h-10-bh);
    glVertex2i(10+bw*i,h-10-bh);
    glEnd();
  }
}
Beispiel #2
0
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);
}
void realTimeClock_t::writeByte (unsigned short port, int val) {
  ___CBTPUSH;

  switch (port) {
  case 0x70:
    m_selected = val;
    break;

  case 0x71:
    if (m_selected < STATUS) {

      struct tm date;
      time_t currentTime = getCurrentTime ();
      localtime_r (&currentTime, &date);
      bool bcdFormat = (m_status[1] & F_BINARY_FORMAT) == 0;
      bool amPmMode = (m_status[1] & F_24_HOUR_MODE) == 0;

      switch (m_selected) {
      case SECONDS:
        date.tm_sec = bcdFormat ? getBinValue (val) : val;
        break;
      case MINUTES:
        date.tm_min = bcdFormat ? getBinValue (val) : val;
        break;
      case HOURS:
        switch (amPmMode << 2 | bcdFormat << 1 | val > 0x7F) {
        case 2:
        case 3: val = getBinValue (val); break;
        case 4: if (val == 12) val = 0; break;
        case 5: val = val != 0x8C ? val + 12 & 0x7F : 12; break;
        case 6: val = val < 0x12 ? getBinValue (val) : 0; break;
        case 7: val = val != 0x92 ? getBinValue (val & 0x7F) + 12 : 12;
        }
        date.tm_hour = val;
        break;
      case DAY_OF_MONTH:
        date.tm_mday = bcdFormat ? getBinValue (val) : val;
        break;
      case MONTH:
        if (bcdFormat) val = getBinValue (val);
        date.tm_mon = val - 1;
        break;
      case YEAR:
        if (bcdFormat) val = getBinValue (val);
        date.tm_year = 100 * (date.tm_year / 100) + val;
      }
      time_t adjustedTime = mktime (&date);
      m_delta += adjustedTime - currentTime;
      m_dateTime = adjustedTime - 10;

    } else if (m_selected == STATUS + 1) {

      m_status[1] &= ~FLAGS_MASK;
      m_status[1] |= val & FLAGS_MASK;

    }
    m_selected = DEFAULT;
    break;
  }

  ___CBTPOP;
}