Skip to content

Instantly share code, notes, and snippets.

@pearcemc
Created April 28, 2015 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pearcemc/e50d2a40072f2bfc5367 to your computer and use it in GitHub Desktop.
Save pearcemc/e50d2a40072f2bfc5367 to your computer and use it in GitHub Desktop.
Plotting functions for multidimensional image arrays.
from pylab import *
import numpy
def grid_sq(fr,ncol,bs,npx=2,bval=0):
Z = fr.shape[0]
z=0
vbar = bval*ones((bs[0],npx))
hbar = bval*ones((npx, (bs[1] + npx)*ncol + npx))
grid = [hbar]
row = [vbar]
while z<Z:
im = fr[z,:].reshape(bs)
row.append(im)
row.append(vbar)
if z%ncol == (ncol - 1):
row = numpy.hstack(row)
grid.append(row)
grid.append(hbar)
row = [vbar]
z += 1
if z%ncol!=0: #if the number of images on the stack isn't an exact multiple of the number of columns
blank = numpy.zeros(bs)
for r_ in range(ncol - z%ncol):
row.append(blank)
row.append(vbar)
row = numpy.hstack(row)
grid.append(row)
grid.append(hbar)
#for ob in grid: print ob.shape
return numpy.vstack(grid)
def grid_blk(fr,ncol,npx=2,bval=0):
Z = fr.shape[2]
bs = fr[:,:,0].shape
z=0
vbar = bval*ones((bs[0],npx))
hbar = bval*ones((npx, (bs[1] + npx)*ncol + npx))
grid = [hbar]
row = [vbar]
while z<Z:
im = fr[:,:,z]
row.append(im)
row.append(vbar)
if z%ncol == (ncol - 1):
row = numpy.hstack(row)
grid.append(row)
grid.append(hbar)
row = [vbar]
z += 1
if z%ncol!=0: #if the number of images on the stack isn't an exact multiple of the number of columns
blank = numpy.zeros(fr[:,:,0].shape)
for r_ in range(ncol - z%ncol):
row.append(blank)
row.append(vbar)
row = numpy.hstack(row)
grid.append(row)
grid.append(hbar)
#for ob in grid: print ob.shape
return numpy.vstack(grid)
def vis_blk(X,gridsz,interpolation='none',cmap='spectral',save=None):
imshow(grid_blk(X,gridsz),interpolation=interpolation,cmap=cmap)
axis('off')
if save:
savefig(save, bbox_inches='tight', pad_inches = 0)
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment