Ejemplo n.º 1
0
  piece_data = {}

  # Setup each axis.
  if args['--plot']:
    figure_grid = gridspec.GridSpec(1, 2)
    figure_grid.update(wspace=0.025, hspace=0.05)
    ax0 = plt.subplot(figure_grid[0, 0])
    ax1 = plt.subplot(figure_grid[0, 1])
    ax0.axis('off')
    ax1.axis('off')
    ax0.set_aspect('equal')
    ax1.set_aspect('equal')

  # Start processing the image.
  print 'processing "%s"..' % filepath
  piece = JigsawPiece(filepath)
  if args['--plot']:
    ax0.imshow(piece.raw_image, aspect='equal')
  piece_data[filepath] = {}
  piece_data[filepath]['raw_image'] = piece.raw_image.tolist()

  # Get contours.
  try:
    piece.segment(low_threshold=low_threshold, high_threshold=high_threshold)
    if args['--plot']:
      ax0.plot(piece.outline[:, 0], -piece.outline[:, 1], color='green')
      ax1.plot(piece.outline[:, 0], piece.outline[:, 1], color='gray')
    piece_data[filepath]['outline'] = piece.outline.tolist()
  except:
    print 'could not find contours for "%s"' % filepath
Ejemplo n.º 2
0
  piece_data = {}

  # Setup each axis.
  if args['--plot']:
    figure_grid = gridspec.GridSpec(1, 2)
    figure_grid.update(wspace=0.025, hspace=0.05)
    ax0 = plt.subplot(figure_grid[0, 0])
    ax1 = plt.subplot(figure_grid[0, 1])
    ax0.axis('off')
    ax1.axis('off')
    ax0.set_aspect('equal')
    ax1.set_aspect('equal')

  # Start processing the image.
  print 'processing "%s"..' % filepath
  piece = JigsawPiece(filepath)
  if args['--plot']:
    ax0.imshow(piece.raw_image, aspect='equal')
  piece_data['raw_image'] = piece.raw_image.tolist()

  # Get contours.
  try:
    piece.segment()
    if args['--plot']:
      ax0.plot(piece.outline[:, 0], -piece.outline[:, 1], color='green')
      ax1.plot(piece.outline[:, 0], piece.outline[:, 1], color='gray')
    piece_data['outline'] = piece.outline.tolist()
  except:
    print 'could not find contours for "%s"' % filepath

  # Set the raw image's axis limits to match the derived data's axis.