2019-12-08 12:02:15 +00:00
|
|
|
from vision.model import Image
|
|
|
|
from typing import List
|
2019-12-08 14:42:30 +00:00
|
|
|
import numpy as np
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
2019-12-08 12:02:15 +00:00
|
|
|
|
|
|
|
|
2019-12-08 14:42:30 +00:00
|
|
|
def extract_average_rgb(pixels: np.array = None,
|
|
|
|
image: Image = None,
|
|
|
|
images: List[Image] = None):
|
|
|
|
|
|
|
|
if pixels is None and image is None and images is None:
|
|
|
|
raise KeyError('no image provided')
|
|
|
|
|
|
|
|
def extract(i):
|
|
|
|
return i.mean(axis=(0, 1))
|
|
|
|
|
|
|
|
if images is not None:
|
|
|
|
length = len(images)
|
|
|
|
for index, image in enumerate(images):
|
|
|
|
logger.debug(f'generating {index} of {length}')
|
|
|
|
image.descriptor = extract(image)
|
|
|
|
return
|
|
|
|
elif image is not None:
|
|
|
|
image.descriptor = extract(image)
|
|
|
|
else:
|
|
|
|
return extract(pixels)
|