return mosaic(images, cols, np.append(m, emptyrows, axis = 0), 0) else: m[-h:, col*w:col*w+w, :] = i return mosaic(images[1:], cols, m, col + 1) tdb = TinyDB(dimensions = WIDTH * HEIGHT * CHANNELS, parse_args = False) p = tdb.arg_parser() p.add_argument("-o", required = True) p.add_argument("-k", type = int, default = 100) p.add_argument("-c", type = int, default = 10) p.add_argument("--seed", type = int, default = -1) p.add_argument("idx", type = int, nargs = '*') args = tdb.parse_args() # number of images n = tdb.rows() # if no index is given select indexes at random idx = [] if len(args.idx) > 0: idx = args.idx else: # select a random set of n images if args.seed != -1: random.seed(args.seed) idx = random.sample(xrange(n), args.k) m = mosaic(images(tdb, idx, WIDTH, HEIGHT, CHANNELS), args.c) # swap color channels because OpenCV uses BGR instead of RGB r = m[:, :, 0]