-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdispims_color.py
34 lines (30 loc) · 1.36 KB
/
dispims_color.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy
import pylab
def dispims_color(M, border=0, bordercolor=[0.0, 0.0, 0.0], *imshow_args, **imshow_keyargs):
""" Display an array of rgb images.
The input array is assumed to have the shape numimages x numpixelsY x numpixelsX x 3
"""
bordercolor = numpy.array(bordercolor)[None, None, :]
numimages = len(M)
M = M.copy()
for i in range(M.shape[0]):
M[i] -= M[i].flatten().min()
M[i] /= M[i].flatten().max()
height, width, three = M[0].shape
assert three == 3
n0 = numpy.int(numpy.ceil(numpy.sqrt(numimages)))
n1 = numpy.int(numpy.ceil(numpy.sqrt(numimages)))
im = numpy.array(bordercolor)*numpy.ones(
((height+border)*n1+border,(width+border)*n0+border, 1),dtype='<f8')
for i in range(n0):
for j in range(n1):
if i*n1+j < numimages:
im[j*(height+border)+border:(j+1)*(height+border)+border,
i*(width+border)+border:(i+1)*(width+border)+border,:] = numpy.concatenate((
numpy.concatenate((M[i*n1+j,:,:,:],
bordercolor*numpy.ones((height,border,3),dtype=float)), 1),
bordercolor*numpy.ones((border,width+border,3),dtype=float)
), 0)
imshow_keyargs["interpolation"]="nearest"
pylab.imshow(im, *imshow_args, **imshow_keyargs)
pylab.show()