示例#1
0
	def fill(self, photo_list, max_photo_usage=20):
		rand_filelist = []
		dist_threshold = 12
		print ("Starting fill…")
		colrowList = []
		for rowi in range (self.height):
			for coli in range (self.width):
				colrowList.append( (coli, rowi) )
		random.shuffle(colrowList)
		# We fill pixels in random order so we can easily limit
		# the number of usages of a photo
		for index, (coli, rowi) in enumerate(colrowList):
			if index % self.width == 0:
				print ("%i/%i points processed (%i%%)" % (index, self.width*self.height, index/(self.width*self.height)))
			pix = self.array[coli,rowi]
			min_distance = 10000
			around_list = []
			for c in (coli-1, coli, coli+1):
				for r in (rowi-1, rowi, rowi+1):
					try:
						around_list.append( self.array[c,r].photo )
					except KeyError:
						None
			choosen = None
			for min_image in photo_list:
				if min_image.used < max_photo_usage and min_image not in around_list:
					tempdist = color.get_distance(pix.target_color, min_image.color)
					if tempdist < min_distance:
						min_distance=tempdist
						choosen = min_image
			self.array[coli,rowi].set_photo(choosen, min_distance)
示例#2
0
	def add_missing(self, photo_list, min_photo_usage=1):
		"""
		Add some photos in the mosaic to respect the min usage parameter
		"""
		to_be_corrected = []
		for min_image in photo_list:
			if min_image.used < min_photo_usage:
				to_be_corrected.append(min_image)
		for min_image in to_be_corrected:
			for nb in range(min_photo_usage-min_image.used):
				min_distance = 10000
				for rowi in range (self.height):
					for coli in range (self.width):
						if self.array[coli,rowi].photo.used > min_photo_usage:
							pix = self.array[coli,rowi]
							tempdist = color.get_distance(pix.target_color, min_image.color)
							if tempdist < min_distance:
								min_distance=tempdist
								choosen_location = (coli,rowi)
				self.array[choosen_location].set_photo(min_image, min_distance)
				print ( "Missing " + min_image.filename + " set at (" + str(choosen_location) + ")" )