Path: blob/master/core/imagelib/equalize_and_stack_square.py
628 views
import numpy as np1import cv223def equalize_and_stack_square (images, axis=1):4max_c = max ([ 1 if len(image.shape) == 2 else image.shape[2] for image in images ] )56target_wh = 999997for i,image in enumerate(images):8if len(image.shape) == 2:9h,w = image.shape10c = 111else:12h,w,c = image.shape1314if h < target_wh:15target_wh = h1617if w < target_wh:18target_wh = w1920for i,image in enumerate(images):21if len(image.shape) == 2:22h,w = image.shape23c = 124else:25h,w,c = image.shape2627if c < max_c:28if c == 1:29if len(image.shape) == 2:30image = np.expand_dims ( image, -1 )31image = np.concatenate ( (image,)*max_c, -1 )32elif c == 2: #GA33image = np.expand_dims ( image[...,0], -1 )34image = np.concatenate ( (image,)*max_c, -1 )35else:36image = np.concatenate ( (image, np.ones((h,w,max_c - c))), -1 )3738if h != target_wh or w != target_wh:39image = cv2.resize ( image, (target_wh, target_wh) )40h,w,c = image.shape4142images[i] = image4344return np.concatenate ( images, axis = 1 )4546