Пример #1
0
int main(int argc, char **argv)
{
  char *inFile1,*inFile2;
  char *outputFile = NULL;
  extern int optind;            /* argv index of the next argument */
  extern char *optarg;          /* current argv[] */
  int c;                        /* option letter from getopt() */
  char ch;
  extern FILE *fLog;            /* output file descriptor, stdout or log file */
  extern int logflag, quietflag;
  int outputflag=0;
  int bandflag=0;
  int strictflag=0;
  int band=0;
  char msg[1024];

  fLog = NULL;
  logflag = quietflag=0;

  /* process command line */
  // FIXME: Might want to add -band1 and -band2 flags that would allow comparing
  // any arbitrary band in file1 to any arbitrary band in file2
  while ((c=getopt(argc,argv,"o:l:b:s:")) != EOF)
  {
    ch = (char)c;
    switch (ch) {
      case 'l':/* -log <filename>, get logfile; this is sorta hacked */
        if (0==strncmp(optarg,"og",2)) {
          sscanf(argv[optind++], "%s", logFile);
          logflag=1;
          fLog = FOPEN(logFile, "w");
        }
        else {
          FREE(outputFile);
          usage(argv[0]);
        }
        break;
      case 'o':/* -output <filename>, get output filename ...
		  empty if no differences */
        if (0==strncmp(optarg,"utput",5)) {
	  outputFile= (char*) CALLOC(1024, sizeof(char));
	  sscanf(argv[optind++], "%s", outputFile);
          outputflag=1;
        }
        else {
          strcpy(outputFile, "");
          outputflag=0;
        }
        break;
      case 'b':/* -band flag */
        if (0==strncmp(optarg,"and",3)) {
          sscanf(argv[optind++], "%d", &band);
          bandflag=1;
        }
        else {
          FREE(outputFile);
          usage(argv[0]);
        }
        break;
      case 's': /* -strict flag */
        if (0==strncmp(optarg,"trict",5)) {
          strictflag=1;
        }
        else {
          FREE(outputFile);
          usage(argv[0]);
        }
        break;
      default:
        FREE(outputFile);
        usage(argv[0]);
        break;
    }
  }
  asfSplashScreen(argc, argv);

  // After parsing out the command line arguments, there should be 2 arguments 
  // left... the two files to compare
  if ((argc-optind) != 2) {
    if ((argc-optind) > 2) {
      printf("\n => Too many inputs.\n");
    }
    if ((argc-optind) < 2) {
      printf("\n => Too few inputs.\n");
    }
    FREE(outputFile);
    usage(argv[0]);
    // not reached
    return 0;
  }
  else {
    // Grab the file names
    inFile1=argv[optind];
    inFile2=argv[optind+1];
  }
  if (strcmp(inFile1, inFile2) == 0) {
    asfPrintError("inFile1 and inFile2 must be different files\n");
  }
  // Set up output redirection for error and log messages
  if (logflag == 0) {
    fLog = NULL;
  }
  if (!outputflag) {
      sprintf(msg, "Missing output file name ...file differences will be "
	      "directed to stderr (only)\n");
      printf("** Warning: ********\n%s** End of warning **\n\n", msg);
  }
  if (outputflag && strcmp(logFile, outputFile) == 0) {
    sprintf(msg, "Log file cannot be the same as the output file:\n"
            "     Log file: %s\n  Output file: %s\n",
            logFile, outputFile);
    if (outputFile) FREE(outputFile);
    asfPrintError(msg);
  }
  if (strictflag) {
    asfPrintWarning("-strict option is not yet implemented -- ignored.\n");
  }
  if (strictflag) {
    asfPrintWarning("-band option is not yet implemented -- ignored.\n");
  }

  char **bands1 = NULL, **bands2 = NULL;
  int num_bands1, num_bands2, complex = 0;
  stats_t *stats1 = NULL, *stats2 = NULL;
  complex_stats_t *complex_stats1 = NULL, *complex_stats2 = NULL;
  psnr_t *psnrs = NULL;
  complex_psnr_t *complex_psnr = NULL;
  shift_data_t *data_shift = NULL;
  diffimage(inFile1, inFile2, outputFile, logFile, &bands1, &bands2, 
	    &num_bands1, &num_bands2, &complex, &stats1, &stats2, 
	    &complex_stats1, &complex_stats2, &psnrs, &complex_psnr, 
	    &data_shift);

  return (0);
}
Пример #2
0
void cu_diffimage(char *testFile, char *referenceFile)
{
  char **bands1 = NULL, **bands2 = NULL;
  int ii, num_bands1, num_bands2, complex = 0;
  stats_t *stats1 = NULL, *stats2 = NULL;
  complex_stats_t *complex_stats1 = NULL, *complex_stats2 = NULL;
  psnr_t *psnrs = NULL;
  complex_psnr_t *complex_psnr = NULL;
  shift_data_t *data_shift = NULL;
  CU_ASSERT_FALSE(diffimage(testFile, referenceFile, NULL, NULL, 
			    &bands1, &bands2, &num_bands1, &num_bands2, 
			    &complex, &stats1, &stats2, 
			    &complex_stats1, &complex_stats2, 
			    &psnrs, &complex_psnr, &data_shift));

  // We assume here that both images have the same bands
  if (complex) {
    for (ii=0; ii<num_bands1; ii++) {
      if (!complex_stats1->i.stats_good) {
	asfForcePrintStatus("\nTest file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s) real part\n", 
			    testFile, bands1[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", complex_stats1->i.min);
	asfForcePrintStatus("Maximum value     : %lf\n", complex_stats1->i.max);
	asfForcePrintStatus("Mean value        : %lf\n", 
			    complex_stats1->i.mean);
	asfForcePrintStatus("Standard deviation: %lf\n", 
			    complex_stats1->i.sdev);
      }
      CU_ASSERT_TRUE(complex_stats1->i.stats_good);
      if (!complex_stats1->q.stats_good) {
	asfForcePrintStatus("\nTest file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s) imaginary part\n", 
			    testFile, bands1[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", complex_stats1->q.min);
	asfForcePrintStatus("Maximum value     : %lf\n", complex_stats1->q.max);
	asfForcePrintStatus("Mean value        : %lf\n", 
			    complex_stats1->q.mean);
	asfForcePrintStatus("Standard deviation: %lf\n", 
			    complex_stats1->q.sdev);
      }
      CU_ASSERT_TRUE(complex_stats1->q.stats_good);
      if (!complex_stats2->i.stats_good) {
	asfForcePrintStatus("\nReference file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s) real part\n", 
			    referenceFile, bands2[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", complex_stats2->i.min);
	asfForcePrintStatus("Maximum value     : %lf\n", complex_stats2->i.max);
	asfForcePrintStatus("Mean value        : %lf\n", 
			    complex_stats2->i.mean);
	asfForcePrintStatus("Standard deviation: %lf\n", 
			    complex_stats2->i.sdev);
      }
      CU_ASSERT_TRUE(complex_stats2->i.stats_good);
      if (!complex_stats2->q.stats_good) {
	asfForcePrintStatus("\nReference file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s) imaginary "
			    "part\n", referenceFile, bands2[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", complex_stats2->q.min);
	asfForcePrintStatus("Maximum value     : %lf\n", complex_stats2->q.max);
	asfForcePrintStatus("Mean value        : %lf\n", 
			    complex_stats2->q.mean);
	asfForcePrintStatus("Standard deviation: %lf\n", 
			    complex_stats2->q.sdev);
      }
      CU_ASSERT_TRUE(complex_stats2->q.stats_good);
      if (!complex_psnr->i.psnr_good) {
	asfForcePrintStatus("\nPeak signal-to-noise ratio test failed!\n");
	asfForcePrintStatus("PSNR (%s): %lf\n", 
			    bands1[ii], complex_psnr->i.psnr);
      }
      CU_ASSERT_TRUE(complex_psnr->i.psnr_good);
      if (!complex_psnr->q.psnr_good) {
	asfForcePrintStatus("\nPeak signal-to-noise ratio test failed!\n");
	asfForcePrintStatus("PSNR (%s): %lf\n", 
			    bands1[ii], complex_psnr->q.psnr);
      }
      CU_ASSERT_TRUE(complex_psnr->q.psnr_good);
    }
  }
  else {
    for (ii=0; ii<num_bands1; ii++) {
      if (!stats1->stats_good) {
	asfForcePrintStatus("\nTest file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s)\n", 
			    testFile, bands1[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", stats1->min);
	asfForcePrintStatus("Maximum value     : %lf\n", stats1->max);
	asfForcePrintStatus("Mean value        : %lf\n", stats1->mean);
	asfForcePrintStatus("Standard deviation: %lf\n\n", stats1->sdev);
      }
      CU_ASSERT_TRUE(stats1->stats_good);
      if (!stats2->stats_good) {
	asfForcePrintStatus("\nReference file statistics test failed!\n");
	asfForcePrintStatus("File name         : %s (%s)\n", 
			    referenceFile, bands2[ii]);
	asfForcePrintStatus("Minimum value     : %lf\n", stats2->min);
	asfForcePrintStatus("Maximum value     : %lf\n", stats2->max);
	asfForcePrintStatus("Mean value        : %lf\n", stats2->mean);
	asfForcePrintStatus("Standard deviation: %lf\n", stats2->sdev);
      }
      CU_ASSERT_TRUE(stats2->stats_good);
      if (!psnrs->psnr_good) {
	asfForcePrintStatus("\nPeak signal-to-noise ratio test failed!\n");
	asfForcePrintStatus("PSNR (%s): %lf\n", bands1[ii], psnrs->psnr);
      }
      CU_ASSERT_TRUE(psnrs->psnr_good);
    }
  }
  if (!data_shift->cert_good) {
    asfForcePrintStatus("\nGeolocation certainty test failed!\n");
    asfForcePrintStatus("Correlation certainty: %.2f\n", 
			data_shift->cert*100.0);
    CU_ASSERT_TRUE(data_shift->cert_good);
  }
  if (!data_shift->dxdy_good) {
    float radial = sqrt(data_shift->dx * data_shift->dx + 
			data_shift->dy * data_shift->dy);
    asfForcePrintStatus("\nGeolocation shift test failed!\n");
    asfForcePrintStatus("dx    : %10.6f\n", data_shift->dx);
    asfForcePrintStatus("dy    : %10.6f\n", data_shift->dy);
    asfForcePrintStatus("radial: %10.6f\n", radial);
    CU_ASSERT_TRUE(data_shift->dxdy_good);
  }
  for (ii=0; ii<num_bands1; ii++)
    FREE(bands1[ii]);
  FREE(bands1);
  for (ii=0; ii<num_bands2; ii++)
    FREE(bands2[ii]);
  FREE(bands2);
  if (stats1)
    FREE(stats1);
  if (stats2)
    FREE(stats2);
  if (complex_stats1)
    FREE(complex_stats1);
  if (complex_stats1)
    FREE(complex_stats1);
  if (psnrs)
    FREE(psnrs);
  if (complex_psnr)
    FREE(complex_psnr);
  FREE(data_shift);
}