コード例 #1
0
ファイル: insertion.c プロジェクト: bourreP/tatouage
void selection(double **Mv,int N,IplImage *img){

	int i,j,k;
	double *ener;
	double En;

	srand(time(NULL));  

	posx=alocavi(((img->height*img->width)/(N*N*5)));
	posy=alocavi(((img->height*img->width)/(N*N*5)));
	ener=malloc(((img->height*img->width)/(N*N*5))*sizeof(double));

	if ((POS=fopen("Resultat/position_bloc.txt","w"))==NULL){
		printf("Erreur ouverture fichier.\n");
		exit (EXIT_FAILURE);
	}

	for(i=0;i<((img->height*img->width)/(N*N*5));i++){
		posx[i] = N*(rand()%((img->width)/N));
		posy[i] = N*(rand()%((img->height)/N));  
		extractionBloc ( Mv, posx[i], posy[i],N, bloc);      // Extraction des blocs
		dct2dim (bloc, blocT,N,N);  // L'énergie se calcule à partie de la DCT des blocs
		En=0;
		for(j=0;j<N;j++)
			for(k=0;k<N;k++)
				En+=blocT[j][k]*blocT[j][k];
		ener[i]=En;
	}

	triAbulles(ener,posx,posy,N); // On trie les blocs par énergie décroissantes

	for (i=0;i<NWB;i++)
		fprintf(POS,"%d %d\n",posx[i],posy[i]); // On enregistre les positions des blocs de plus haute énergie dans POS

	fclose(POS);
	free(ener);
}
コード例 #2
0
int *grau_vertices(no **rede, int n) {
  // -------------------------------------
  // Conta o grau de cada vértice da rede.
  // -------------------------------------

  int i, *k;
  no *p;

  k=alocavi(n);

  for(i=0;i<n;i++)
    for(p=rede[i]->prox;p!=NULL;p=p->prox)
      k[i]++;

  return(k);

}
コード例 #3
0
ファイル: insertion.c プロジェクト: bourreP/tatouage
void selection(double **Mv,int N,IplImage *img){

  int i,j,z;
  int g=0;
  int mes_dec;
  int mes_i;
  double key_i;
  double aux1,aux2,w;           // Intermédiaires de calcul
  double Q;                     // Valeur test pour l'insertion
  double proj1,proj2;           // Projetés sur le masque

  float masque_t[4][4]= {
    {0,0.58,1.2,2.39},
    {0.58,1.12,1.49,2.3},
    {1.2,1.49,3.07,4.35},
    {2.39,2.3,4.35,7.25}
  };
  float Norme_masque=11.4492;
  
  double aux;
  double **blocT2;
  blocT2=alocamd(N,N);

  srand(time(NULL));  

  posx=alocavi(NWB);
  posy=alocavi(NWB);

  if ((POS=fopen("Resultat/position_bloc.txt","w"))==NULL){
    printf("Erreur ouverture fichier.\n");
    exit (EXIT_FAILURE);
  }

  if ((Mark=fopen("Resultat/Marque.txt","r"))==NULL){
    printf("Erreur ouverture fichier.\n");
    exit (EXIT_FAILURE);
  }

  if ((KEY=fopen("Resultat/key.txt","r"))==NULL){
    printf("Erreur ouverture fichier.\n");
    exit (EXIT_FAILURE);
  }

  for(z=0;z<NWB;z++){

    fscanf(Mark,"%d\n",&mes_i);
    fscanf(KEY,"%lf\n",&key_i);
    g=0;

    while (g!=6){

      proj1=0;
      proj2=0;
      posx[z] = N*(rand()%((img->width)/N));
      posy[z] = N*(rand()%((img->height)/N));  
      extractionBloc ( Mv, posx[z], posy[z],N, bloc);      // Extraction des blocs
      dct2dim (bloc, blocT,N,N);  // L'énergie se calcule à partie de la DCT des blocs
      for (i=0;i<N;i++)                // Copie de blocT dans blocT2
	for (j=0;j<N;j++)
	  blocT2[i][j]=blocT[i][j];
      
  
      for (i=0;i<N;i++)               // Transposée de blocT
	for(j=0;j<N;j++){

	  aux=blocT[i][j];
	  blocT[i][j]=blocT[j][i];
	  blocT[j][i]=aux;
	}
  
      for (i=0;i<N;i++)
	for(j=0;j<N;j++)               // Projection sur le masque
	  proj1+=(double)blocT[i][j]*masque_t[i][j]/Norme_masque;

      aux1= floor((proj1-pas*((float)mes_i/2+key_i))/pas+0.5);
      w = a*(aux1*pas-(proj1-pas*((float)mes_i/2+key_i)));  

      /*insertion*/

      for (i=0;i<N;i++)
	for(j=0;j<N;j++){
	  //blocT[i][j]=0;
	  blocT[i][j]=blocT2[i][j]+w*masque_t[i][j]/Norme_masque;
	}

      /*detection immédiate*/

      for (i=0;i<N;i++)
	for(j=0;j<N;j++)
	  proj2+=(double)blocT[i][j]*masque_t[i][j]/Norme_masque;

      aux2=floor((proj2-pas*key_i)/(pas)+0.5);
      Q = aux2*pas-(proj2-pas*key_i);

      if(mes_i==0 && fabs(Q)<(1-a)*pas/10){
	fprintf(POS,"%d %d\n",posx[z],posy[z]);
	g=6;
      }
  
      if(mes_i==1 && fabs(Q)>(1-a)*pas/2){
	fprintf(POS,"%d %d\n",posx[z],posy[z]);
	g=6;
      }
    }
  } 

  dalocd(blocT2,N);
  fclose(POS);
  fclose(Mark);
  fclose(KEY);
}
コード例 #4
0
void opiniao(int n, no **rede, int T, double semente, double J, double epsilon, double q, FILE *out) {
  // ---------------------------------------------------
  // Aqui é a parte da simulação da dinâmica de opinião.
  // ---------------------------------------------------

  int t=0, i; // passo monte-carlo e iterador de sítios da rede
  int *k, *s; // vetor de conectividade e com o estado dos sitios;
  double *h, prob, rho=0; // campo local de cada sítio e taca de transição
  no *p; // iterador de sítios da re
  
  // Iniciando a galera
  s=alocavi(n);
  h=alocavd(n);
  k=grau_vertices(rede,n);
  srand(semente);

  // Estado inicial aleatório
  for(i=0;i<n;i++)
    s[i]=rand()%2;
  
  for(i=0;i<n;i++)
    rho+=s[i];
  rho/=((double)n);
  // Primeiro ponto na saida
  fprintf(out, "%d %lf\n", t, rho);

  // O monte-carlo começa aqui
  for(t=0;t<T;t++) {

    rho=0;

    // Calcular o vetor h dos sítios
    for(i=0;i<n;i++) {
      for(p=rede[i]->prox;p!=NULL;p=p->prox)
	h[i]+=s[p->rotulo];
      h[i]=h[i]/(double)k[i];
    }

      // Atualiza os sítios
    for(i=0;i<n;i++) {
      prob=rand()/(double)RAND_MAX;
      if(prob<tau(J,epsilon,q,h[i])) {
	if(s[i]==0) s[i]=1;
      }
      else
	if(s[i]==1) s[i]=0;
    }

    // Calcula a densidade
    for(i=0;i<n;i++)
      rho+=s[i];
    rho/=((double)n);

    // Imprime saída
    fprintf(out, "%d %lf\n", t, rho);

  }

  free(s);
  free(h);
  free(k);
  
}