Пример #1
0
/* Image_Branch_Code(): Build branch code for an image.
 *
 * Note: The caller is responsible for clearing the returned pointer. No aliasing
 *       is allowed between the input pointers.
 *
 * Args:  image - input image.
 *        code - output coded image. A new image will be created if it is NULL.
 *        link - An array for storing intermediate results. It must be NULL or 
 *               have the length of the number of pixels.
 *        seed - starting pixel.
 *
 * Return: code image. The intensity of a pixel is its branch label.
 */
Image* Image_Branch_Code(Image *image, Image *code, int *link, uint16 *edge, int seed)
{
  assert(image != NULL);

  if (image->kind != GREY) {
    TZ_ERROR(ERROR_DATA_TYPE);
  }

  if (image->array[seed] == 0) {
    TZ_WARN(ERROR_OTHER);
    TRACE("The seed is in the background.");
    return NULL;
  }
  
  init_imginfo(image->width, image->height, 1);
 
  int link_owner = FALSE;

  if (link == NULL) {
    link = (int*)Guarded_Malloc(sizeof(int) * cnpixel, "Image_Branch_Code");
    link_owner = TRUE;
  }

  if (code == NULL) {
    code = Make_Image(GREY16, image->width, image->height);
  }
  
  uint16 *code_array = (uint16 *) code->array;
  int neighbor[8];

  branch_code(image->array, code_array, link, edge, image->width, image->height, 1,
	     seed, neighbor);

  if (link_owner == TRUE) {
    free(link);
  }

  return code;
}
Пример #2
0
int main(int argc, char *argv[])
{ char  *whisker_file_name, *bar_file_name, *prefix;
  size_t prefix_len;
  FILE  *fp;
  Image *bg=0, *image=0;
  int    i,depth;

  char * movie;

  /* Process Arguments */
  Process_Arguments(argc,argv,Spec,0);
  { char* paramfile = "default.parameters";
    if(Load_Params_File("default.parameters"))
    { warning(
        "Could not load parameters from file: %s\n"
        "Writing %s\n"
        "\tTrying again\n",paramfile,paramfile);
      Print_Params_File(paramfile);
      if(Load_Params_File("default.parameters"))
        error("\tStill could not load parameters.\n");
    }
  }

  prefix = Get_String_Arg("prefix");
  prefix_len = strlen(prefix);
  { char *dot = strrchr(prefix,'.');  // Remove any file extension from the prefix
    if(dot) *dot = 0;
  }
  whisker_file_name = (char*) Guarded_Malloc( (prefix_len+32)*sizeof(char), "whisker file name");
  bar_file_name = (char*) Guarded_Malloc( (prefix_len+32)*sizeof(char), "bar file name");
  memset(whisker_file_name, 0, (prefix_len+32)*sizeof(char) );
  memset(bar_file_name ,    0, (prefix_len+32)*sizeof(char) );

  sprintf( whisker_file_name, "%s.whiskers", prefix );
  sprintf(  bar_file_name, "%s.bar", prefix );

  progress("Loading...\n"); fflush(stdout);
  movie = Get_String_Arg("movie");
  TRY(image = load(movie,0,&depth),ErrorOpen);

  progress("Done.\n");

  // No background subtraction (init to blank)
  { bg = Make_Image( image->kind, image->width, image->height );
    memset(bg->array, 0, bg->width * bg->height );
  }
  Free_Image( image );

#if 0
  /*
   * Bar tracking
   */
  if( !Is_Arg_Matched("--no-bar") )
  { double x,y;
    BarFile *bfile = Bar_File_Open( bar_file_name, "w" );
    progress( "Finding bar positions\n" );
    for( i=0; i<depth; i++ )
    { progress_meter(i, 0, depth-1, 79, "Finding     post: [%5d/%5d]",i,depth);
      image = load(movie,i,NULL);
      invert_uint8( image );
      Compute_Bar_Location(   image,
                              &x,             // Output: x position
                              &y,             // Output: y position
                              15,             // Neighbor distance
                              15,             // minimum contour length
                              0,              // minimum intensity of interest
                              255,            // maximum intentity of interest
                              10.0,           // minimum radius of interest
                              30.0          );// maximum radius of interest
      Bar_File_Append_Bar( bfile, Bar_Static_Cast(i,x,y) );
      Free_Image(image);
    }
    Bar_File_Close( bfile );
  }
#endif

  /*
   * Trace whisker segments
   */
  //if( !Is_Arg_Matched("--no-whisk") )
  { int           nTotalSegs = 0;
    Whisker_Seg   *wv;
    int wv_n; 
    WhiskerFile wfile = Whisker_File_Open(whisker_file_name,"whiskbin1","w");

    if( !wfile )
    { fprintf(stderr, "Warning: couldn't open %s for writing.", whisker_file_name);
    } else
    { //int step = (int) pow(10,round(log10(depth/100)));
      for( i=0; i<depth; i++ )
      //for( i=450; i<460; i++ )
      //for( i=0; i<depth; i+= step )
      { int k;
        TRY(image=load(movie,i,NULL),ErrorRead);
        progress_meter(i, 0, depth, 79, "Finding segments: [%5d/%5d]",i,depth-1);
        wv = find_segments(i, image, bg, &wv_n);                                                // Thrashing heap
        k = Remove_Overlapping_Whiskers_One_Frame( wv, wv_n, 
                                                   image->width, image->height, 
                                                   2.0,    // scale down by this
                                                   2.0,    // distance threshold
                                                   0.5 );  // significant overlap fraction
        Whisker_File_Append_Segments(wfile, wv, k);
        Free_Whisker_Seg_Vec( wv, wv_n );
        Free_Image(image);
      }
      printf("\n");
      Whisker_File_Close(wfile);
    }
  }
  load(movie,-1,NULL); // Close (and free)
  if(bg) Free_Image( bg );
  return 0;
ErrorRead:
  load(movie,-1,NULL); // Close (and free)
  if(bg) Free_Image( bg );
  error("Could not read frame %d from %s"ENDL,i,movie);
  return 1;
ErrorOpen:
  error("Could not open %s"ENDL,movie);
  return 2;
}
Пример #3
0
//
//  RL_Make_Image: C
// 
// Allocate a new image of the given size.
// 
// Returns:
//     A pointer to an image series, or zero if size is too large.
// Arguments:
//     width - the width of the image in pixels
//     height - the height of the image in lines
// Notes:
//     Images are allocated with REBOL's internal memory manager.
//     Image are automatically garbage collected if there are
//     no references to them from REBOL code (C code does nothing.)
//
RL_API REBSER *RL_Make_Image(u32 width, u32 height)
{
    REBSER *ser = Make_Image(width, height, FALSE);
    MANAGE_SERIES(ser);
    return ser;
}