Last active
December 31, 2016 10:15
-
-
Save RGBD/bab287f3f2663e83901cdadaa8e6f767 to your computer and use it in GitHub Desktop.
Python fancy show list of images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fancy_show(imgs, *, n_cols=None, fig_dim=None): | |
if type(imgs) == numpy.ndarray: | |
imgs = [imgs] | |
if len(imgs) == 1: | |
n_rows = 1 | |
n_cols = 1 | |
if fig_dim == None: | |
fig_dim = 10 | |
figsize = (fig_dim, fig_dim) | |
else: | |
if n_cols == None: | |
n_cols = min(len(imgs), 3) | |
n_rows = int(ceil(len(imgs) / n_cols)) | |
if fig_dim == None: | |
fig_dim = 15 | |
figsize = (fig_dim, fig_dim / n_cols * n_rows) | |
fig = plt.figure(figsize=figsize) | |
for i, img in enumerate(imgs): | |
ax = fig.add_subplot(n_rows, n_cols, i + 1) | |
ax.imshow(img, cmap='gray', interpolation='none') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment