Last active
July 25, 2017 02:59
-
-
Save wassname/8dfaf6f25b540ef1a111868fff5cc03b to your computer and use it in GitHub Desktop.
imshow a panel 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
import numpy as np | |
from matplotlib import pyplot as plt | |
def subimshow(image, title=''): | |
""" | |
Show each band seperately. | |
The shape si a square or rectangle of images | |
image: array of shape (channel, height, width) | |
""" | |
nb_bands = image.shape[0] | |
ncols=int(np.ceil(np.sqrt(image.shape[0]))) | |
nrows=int(np.ceil(nb_bands/float(ncols))) | |
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, sharex=True, sharey=False, figsize=(15,15)) | |
if title: fig.suptitle('{} shape={} min={:2.2f} mean{:2.2f} max={:2.2f} std={:2.2f} dtype={}'.format(title, image.shape, image.min(), image.mean(), image.max(), image.std(), image.dtype), fontsize=14) | |
ax=ax.flatten() | |
for i in range(len(image)): | |
d=image[i].astype(float) | |
d/=d.sum() | |
ax[i].imshow(d) | |
ax[i].set_title('Band %s'%i) | |
ax[i].autoscale(False) | |
plt.show() | |
subimshow(np.random.random((5,50,50)),'5 bands') | |
subimshow(np.random.random((13,50,50)), '13 bands') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment