def compare_all_to(self, image, sort=True): ''' if sort is falsy, a generator is returned and results come in the order images were loaded, else a sorted list is returned ''' if not self.images: raise IndexError('No images loaded') # this stupid conversion has to happen for whatever reason image = image.convert('RGB') image_data = get_data(image) comparisons = ((other_image, compare_data(image_data, other_image_data)) for other_image, other_image_data in self.images) if sort: return sorted(comparisons, key=lambda x:x[1], reverse=True) return comparisons
def add(self, file_path): image = Image.open(file_path) self.images.append((image, get_data(image)))
def add(self, image): self.images.append((image, get_data(image)))