Ejemplo n.º 1
0
/* Start of main progam */
int main(int argc, char *argv[])
{
  char szOut[255], szImg1[255], szImg2[255], *maskFile;
  int x1, x2, y1, y2;
  int goodPoints=0, attemptedPoints=0;
  FILE *fp_output;
  meta_parameters *masterMeta, *slaveMeta;
  int logflag=FALSE, ampFlag=TRUE, currArg=1;
  
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key,"-log","--log",NULL)) {
      CHECK_ARG(1);
      strcpy(logFile,GET_ARG(1));
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key,"-mask","--mask",NULL)) {
      CHECK_ARG(1);
      maskFile = GET_ARG(1);
    }
    else {
      printf("\n**Invalid option: %s\n", argv[currArg-1]);
      usage(argv[0]);
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  }

  // Fetch required arguments 
  strcpy(szImg1,argv[argc - 3]);
  strcpy(szImg2,argv[argc - 2]);
  strcpy(szOut, argv[argc - 1]);

  /* Read metadata */
  masterMeta = meta_read(szImg1);
  slaveMeta = meta_read(szImg2);
  if (masterMeta->general->line_count != slaveMeta->general->line_count ||
      masterMeta->general->sample_count != slaveMeta->general->sample_count)
    asfPrintWarning("Input images have different dimension!\n");
  else if (masterMeta->general->data_type != slaveMeta->general->data_type)
    asfPrintError("Input image have different data type!\n");
  else if (masterMeta->general->data_type > 5 &&
	   masterMeta->general->data_type != COMPLEX_REAL32)
    asfPrintError("Cannot compare raw images for offsets!\n");
  lines = masterMeta->general->line_count;
  samples = masterMeta->general->sample_count;
  if (masterMeta->general->data_type == COMPLEX_REAL32) {
    srcSize = 32;
    ampFlag = FALSE;
    cZero = Czero();
  }

  /* Create output file */
  fp_output=FOPEN(szOut, "w");
  
  /* Loop over grid, performing forward and backward correlations */
  while (getNextPoint(&x1,&y1,&x2,&y2))
      {
	float dx=0.0, dy=0.0, snr=0.0, dxFW, dyFW, snrFW, dxBW, dyBW, snrBW;
	attemptedPoints++;

        // Check bounds and mask
	if (!(outOfBounds(x1, y1, srcSize, maskFile)))
	{
	  /* ...check forward correlation... */
	  if (ampFlag) {
	    if (!(findPeak(x1,y1,szImg1,x2,y2,szImg2,&dxFW,&dyFW,&snrFW))) {
	      attemptedPoints--;
	      continue; /* next point if chip in complete background fill */
	    }
	  }
	  else {
	    getPeak(x1,y1,szImg1,x2,y2,szImg2,&dxFW,&dyFW,&snrFW);
	  }
	  if ((!ampFlag && snrFW>minSNR) || (ampFlag)) {
	    /* ...check backward correlation... */
	    if (ampFlag) {
	      if (!(findPeak(x2,y2,szImg2,x1,y1,szImg1,&dxBW,&dyBW,&snrBW))) {
		attemptedPoints--;
                continue; /* next point if chip in complete background fill */
	    printf("dxFW: %.2f, dyFW: %.2f\n", dxFW, dyFW);
	      }
	    }
	    else {
	      getPeak(x2,y2,szImg2,x1,y1,szImg1,&dxBW,&dyBW,&snrBW);
	    }

	    dxBW*=-1.0;dyBW*=-1.0;
	    if (((!ampFlag && snrFW>minSNR) || (ampFlag)) &&
		(fabs(dxFW-dxBW) < maxDisp) &&
		(fabs(dyFW-dyBW) < maxDisp))
	      {
		dx = (dxFW+dxBW)/2;
		dy = (dyFW+dyBW)/2;
		snr = snrFW*snrBW;
		if (dx < maxDxDy && dy < maxDxDy) goodPoints++;
	      }
	  }
	  fprintf(fp_output,"%6d %6d %8.5f %8.5f %4.2f\n",
		  x1, y1, x2+dx, y2+dy, snr);
	  fflush(fp_output);
	}
      }
  if (goodPoints < attemptedPoints)
    printf("\n   WARNING: %i out of %i points moved by "
	   "more than one pixel!\n\n", 
	   (attemptedPoints-goodPoints), attemptedPoints);
  else 
    printf("\n   There is no difference between the images\n\n");

  FCLOSE(fp_output);
  FREE(masterMeta);
  FREE(slaveMeta);  

  return(0);
}
Ejemplo n.º 2
0
int Map::getObstacles() const
{
	return (getWater() + getPeak());
}