示例#1
0
/* Sobel filter (horizontal and veritical differentiation) */
void sobel_filtering()
{
  
  int x, y, i, j;
 
  //The 3x3 window of image
  unsigned char image_window[3][3];
  int rows = 0, cols = 0;

  /* Initialization of image2[y][x] */
  x_size2 = x_size1;
  y_size2 = y_size1;
  for (y = 0; y < y_size2; y++) {
    for (x = 0; x < x_size2; x++) {
      image2[y][x] = 0;
    }
  }

  for (y = 1; y < y_size1 - 1; y++) {
    for (x = 1; x < x_size1 - 1; x++) {
    rows=0; 
    cols = 0;
    for (j = -1; j <= 1; j++) {
	  for (i = -1; i <= 1; i++) {
      image_window[rows][cols] = ( image1[y+j][x+i] );
      cols++;
      }    
      rows++;
      cols = 0;
    }
#ifdef AXC
	unsigned char ret;
//#pragma axc_memoize [(0:5)]{2} 
//[(argument:error bound), ..{out arguments}
//(0:5),(1:5),..]{3}
#pragma axc_memoize [(0:5),(1:5),(2:5),(3:5),(4:5),(6:5),(7:5),(8:5)]{9} 
	kernel_filter(image_window[0][0], image_window[0][1], image_window[0][2],  image_window[1][0],  image_window[1][1],  image_window[1][2],  image_window[2][0],  image_window[2][1],  image_window[2][2], image_window, &ret); 
	image2[y][x] = ret; 
#else
    image2[y][x] = kernel_filter(image_window); 
#endif
    }
  }

}
示例#2
0
int fftMatch_opt(char *inFile1, char *inFile2, float *offsetX, float *offsetY)
{ 
  // Generate temporary directory
  char tmpDir[1024];
  char metaFile[1024], outFile[1024], sarFile[1024], opticalFile[1024];
  char *baseName = get_basename(inFile1);
  strcpy(tmpDir, baseName);
  strcat(tmpDir, "-");
  strcat(tmpDir, time_stamp_dir());
  create_clean_dir(tmpDir);
  
  // Cutting optical to SAR extent
  asfPrintStatus("Cutting optical to SAR extent ...\n");
  sprintf(metaFile, "%s.meta", inFile1);
  sprintf(outFile, "%s%c%s_sub.img", tmpDir, DIR_SEPARATOR, inFile2);
  trim_to(inFile2, outFile, metaFile);
  
  // Clipping optical image including blackfill
  asfPrintStatus("\nClipping optical image including blackfill ...\n");
  meta_parameters *metaOpt = meta_read(outFile);
  meta_parameters *metaSAR = meta_read(metaFile);
  int line_count = metaSAR->general->line_count;
  int sample_count = metaSAR->general->sample_count;
  float *floatLine = (float *) MALLOC(sizeof(float)*sample_count);
  unsigned char *byteLine = (unsigned char *) MALLOC(sizeof(char)*sample_count);
  FILE *fpOptical = FOPEN(outFile, "rb");
  sprintf(sarFile, "%s.img", inFile1);
  FILE *fpSAR = FOPEN(sarFile, "rb");
  sprintf(outFile, "%s%c%s_mask.img", tmpDir, DIR_SEPARATOR, inFile2);
  sprintf(metaFile, "%s%c%s_mask.meta", tmpDir, DIR_SEPARATOR, inFile2);
  FILE *fpOut = FOPEN(outFile, "wb");
  int ii, kk;
  for (ii=0; ii<line_count; ii++) {
    get_float_line(fpSAR, metaSAR, ii, floatLine);
    get_byte_line(fpOptical, metaOpt, ii, byteLine);
    for (kk=0; kk<sample_count; kk++) {
      if (!FLOAT_EQUIVALENT(floatLine[kk], 0.0))
        floatLine[kk] = (float) byteLine[kk];
    }
    put_float_line(fpOut, metaSAR, ii, floatLine);
  }
  FCLOSE(fpOptical);
  FCLOSE(fpSAR);
  FCLOSE(fpOut);
  meta_write(metaSAR, metaFile);

  // Edge filtering optical image
  asfPrintStatus("\nEdge filtering optical image ...\n");
  sprintf(opticalFile, "%s%c%s_sobel.img", tmpDir, DIR_SEPARATOR, inFile2);
  kernel_filter(outFile, opticalFile, SOBEL, 3, 0, 0);

  // Edge filtering SAR image
  asfPrintStatus("\nEdge filtering SAR image ...\n");
  sprintf(sarFile, "%s%c%s_sobel.img", tmpDir, DIR_SEPARATOR, inFile1);
  kernel_filter(inFile1, sarFile, SOBEL, 3, 0, 0);

  // FFT matching on a grid
  asfPrintStatus("\nFFT matching on a grid ...\n");
  float certainty;
  fftMatch_proj(sarFile, opticalFile, offsetX, offsetY, &certainty);

  // Clean up
  remove_dir(tmpDir);

  return (0);
}