def stitch_images(images, margin=<NUM_LIT:5>, cols=<NUM_LIT:5>):
if len(images) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>h, w, c = images[<NUM_LIT:0>].shape<EOL>n_rows = int(math.ceil(len(images) / cols))<EOL>n_cols = min(len(images), cols)<EOL>out_w = n_cols * w + (n_cols - <NUM_LIT:1>) * margin<EOL>out_h = n_rows * h + (n_rows - <NUM_LIT:1>) * margin<EOL>stitched_images = np.zeros((out_h, out_w, c), dtype=images[<NUM_LIT:0>].dtype)<EOL>for row in range(n_rows):<EOL><INDENT>for col in range(n_cols):<EOL><INDENT>img_idx = row * cols + col<EOL>if img_idx >= len(images):<EOL><INDENT>break<EOL><DEDENT>stitched_images[(h + margin) * row: (h + margin) * row + h,<EOL>(w + margin) * col: (w + margin) * col + w, :] = images[img_idx]<EOL><DEDENT><DEDENT>return stitched_images<EOL>
Utility function to stitch images together with a `margin`.

    Args:
        images: The array of 2D images to stitch.
        margin: The black border margin size between images (Default value = 5)
        cols: Max number of image cols. New row is created when number of images exceed the column size.
            (Default value = 5)

    Returns:
        A single numpy image array comprising of input images.