Пример #1
0
 def __init__(self, imagepath):
   # Base options
   self.base_image = ImageManager.newFromPath(imagepath)
   self.base_image.load()
   self.colours = None
   self.collage_image = CollageImage.new(self.base_image.size)
   self.output_image_savepath = None
   self.images_folder = None
   self.debug = False
   self.log = None
   # Collage options
   self.precision = DEFAULT_PRECISION
   self.threshold = DEFAULT_THRESHOLD
   self.near_size = DEFAULT_NEAR_SIZE
   self.scale_factor = 1
   self.shuffle_colours = False
   self.shuffle_colours_distance = DEFAULT_SHUFFLE_COLOURS_DISTANCE
   self.shuffle_geometry = DEFAULT_SHUFFLE_GEOMETRY
   # Workflow options
   self.show_partials = False
   # Class variables
   self.sector_size = None
   self.collage_image_size = None
   self.collage_image_size_precision = DEFAULT_COLLAGE_IMAGE_SIZE_PRECISION
   self.collage_image_size_min = None # Enforced limit
   self.collage_image_size_max_width = None # Non-enforced limit
   self.collage_image_size_max_height = None # Non-enforced limit
   # Collage variables
   self.collage_same_height_streak = DEFAULT_COLLAGE_SAME_HEIGHT_STREAK
   self.collage_same_height_streak_max = DEFAULT_COLLAGE_SAME_HEIGHT_STREAK
Пример #2
0
 def loadColoursComplete(self):
   self.log.info('loadColoursComplete == Loading colours')
   self.log.debug('loadColoursComplete == Collage image size: ' + str(self.collage_image_size))
   self.log.debug('loadColoursComplete == Collage image size precision: ' + str(self.collage_image_size_precision))
   self.log.debug('loadColoursComplete == Sector size: ' + str(self.sector_size))
   # Set min size
   self.collage_image_size_min = int(numpy.ceil(self.collage_image_size * self.collage_image_size_precision))
   self.log.info('loadColoursComplete == Min size: ' + str(self.collage_image_size_min))
   # Save width and height
   images_width = []
   images_height = []
   print('Loading resources')
   self.log.info('loadColoursComplete == Loading from images')
   loading_folder = self.images_folder
   for name in os.listdir(loading_folder):
     path = os.path.join(loading_folder, name)
     if not os.path.isdir(path) and self.hasValidExtension(path): # Ignore folders and invalid files
       try:
         img = ImageManager.new(path)
         img.setSectorSize(self.sector_size)
         # resize
         img.resizeMaximal(self.collage_image_size)
         # partition
         img.partition()
         # load colour
         colour = CollageImage.newColour(img, self.sector_size)
         # add to self.colours
         self.colours.append(colour)
         # add sizes
         images_width.append(img.width)
         images_height.append(img.height)
         # Show progress
         sys.stdout.write('.')
         sys.stdout.flush()
       except Exception as error:
         self.log.info('loadColoursComplete == Error loading: ' + path)
         print('\n*Error loading ' + path)
         continue
   self.collage_image_size_avg_width = int(numpy.ceil(numpy.mean(images_width)))
   self.collage_image_size_avg_height = int(numpy.ceil(numpy.mean(images_height)))
   self.collage_image_size_max_width = int(numpy.max(images_width))
   self.collage_image_size_max_height = int(numpy.max(images_height))
   self.log.info('loadColoursComplete == Collage image size avg width: ' + str(self.collage_image_size_avg_width))
   self.log.info('loadColoursComplete == Collage image size avg height: ' + str(self.collage_image_size_avg_height))
   self.log.info('loadColoursComplete == Collage image size max width: ' + str(self.collage_image_size_max_width))
   self.log.info('loadColoursComplete == Collage image size max height: ' + str(self.collage_image_size_max_height))
   print('\nLoaded ' + str(len(self.colours)) + ' resources')
Пример #3
0
  collager.setScaleFactor(scale_factor)
  collager.setShuffleColours(shuffle)
  collager.setShuffleColoursDistance(shuffle_distance)
  collager.setShuffleGeometry(shuffle_geometry)
  collager.setThreshold(threshold)
  collager.setNearSize(near_size)
  collager.setShowPartials(show_partials)
  try:
    collager.collage()
    print('Resizing and saving (it may require some time)')
  except Exception as error:
    print(str(error))
    collager.save()
    sys.exit(2)
  collager.save()
else:
  print('Loading schema')
  # Load collage image
  collage_image = CollageImage.newFromSchema(schema_filepath, images_folder)
  if collage_image is None:
    print("Error reloading collage, exiting.")
    sys.exit(3)
  # Apply mask
  if apply_mask is not None:
    collage_image.applyMask(apply_mask)
  # Resize and save
  print('Resizing and saving')
  collage_image.saveResized(output_image, scale_factor)
  
sys.exit(0)