Exemplo n.º 1
0
int _tmain(int nArgC, _TCHAR* ppArgv[])
{
	if (nArgC < 3)
	{
		std::cout << "Must input two filename of images." << std::endl;
		return -1;
	}

	if (!PathFileExistsW(ppArgv[1]) || !PathFileExistsW(ppArgv[2]))
	{
		std::cout << "At least one file not exsist." << std::endl;
		return -2;
	}

	float fMI;
	HRESULT hr = MutualInformation(ppArgv[1], ppArgv[2], fMI);
	if (S_OK == hr)
	{
		std::cout << fMI << std::endl;
	}
	else
	{
		std::cout << "Error: " << std::hex << hr << std::endl;
	}
	system("pause");
	return 0;
}
Exemplo n.º 2
0
/*
  ---------------------------------------------------------------------
  
  ---------------------------------------------------------------------
*/
int
GetDecorrelationStepMB_OD(double *H,
		       double linC,
		       struct node_gra **nlist,
		       struct group **glist,
		       struct group *part,
		       int nnod,
		       int **G2G,
		       int *n2gList,
		       double **LogChooseList,
		       int LogChooseListSize,
		       double *LogFactList, int LogFactListSize,
		       double *HarmonicList,
		       gsl_rng *gen,
		       char verbose_sw)
{
  struct group *partRef;
  int step, x1, x2;
  double y1, y2;
  double mutualInfo;
  int rep, nrep=10;
  double *decay, meanDecay, sigmaDecay, result;
  int norm=0;

  x2 = nnod / 5;
  x1 = x2 / 4;

  /* Get the nrep initial estimates */
  decay = allocate_d_vec(nrep);
  for (rep=0; rep<nrep; rep++) {
    switch (verbose_sw) {
    case 'q':
      break;
    default:
      fprintf(stderr, "#\n# Estimating decorrelation time (%d/%d)\n",
	      rep + 1, nrep);
      break;
    }
    partRef = CopyPartition(part);
    for (step=0; step<=x2; step++) {
      LSMCStepMB_OD(1, H, linC, nlist, glist, part,
		 nnod, G2G, n2gList,
		 LogChooseList, LogChooseListSize,
		 LogFactList, LogFactListSize, HarmonicList,
		 gen);
      if (step == x1)
	y1 = MutualInformation(partRef, part);
    }
    y2 = MutualInformation(partRef, part);
    RemovePartition(partRef);
    decay[rep] = 2. * CalculateDecay(nnod, x1, y1, x2, y2);
    switch (verbose_sw) {
    case 'q':
      break;
    default:
      fprintf(stderr, "# Decorrelation time (estimate %d) = %g\n",
	      rep + 1, decay[rep]);
      break;
    }
    if (decay[rep] < 0) {
      rep--;
      switch (verbose_sw) {
      case 'q':
	break;
      default:
	fprintf(stderr, "#\tignoring...\n");
	break;
      }
    }
  }
  
  /* Get rid of bad estimates (Chauvenet criterion)  */
  meanDecay = mean(decay, nrep);
  sigmaDecay = stddev(decay, nrep);
  result = meanDecay * nrep;
  for (rep=0; rep<nrep; rep++) {
    if (fabs(decay[rep] - meanDecay) / sigmaDecay > 2) {
      result -= decay[rep];
      switch (verbose_sw) {
      case 'q':
	break;
      default:
	fprintf(stderr, "# Disregarding estimate %d\n", rep + 1);
	break;
      }
    }
    else {
      norm++;
    }
  }
  
  /* Clean up */
  free_d_vec(decay);

  return result / norm;
}