comparison image_tools.py @ 441:a2e8de4669cd

merge
author Pascal Lamblin <lamblinp@iro.umontreal.ca>
date Thu, 21 Aug 2008 13:55:43 -0400
parents d7ed780364b3
children
comparison
equal deleted inserted replaced
440:18dbc1c11647 441:a2e8de4669cd
1
2 import numpy
3
4
5 def make_weights_image(mat, xres, yres, i, j, nrow, ncol):
6 """
7 Displays the filters implemented by a weight matrix.
8
9 Each filter corresponds to a row of mat and will be represented
10 by a xres*yres image.
11
12 Units from i to j will be included in the picture.
13
14 The picture will have nrow rows of filters and ncol columns
15 of filters. Unused spots for filters will be filled with zeros.
16
17 The return value is a matrix suitable for display with
18 matplotlib's imshow.
19 """
20
21 assert j > i
22 n = j - i
23 result = numpy.zeros((ncol * xres, nrow * yres))
24 submat = mat[i:j]
25 for k, row in enumerate(submat):
26 x = (k % ncol)*xres
27 y = (k / ncol)*yres
28 entry = row.reshape((xres, yres))
29 lmin, lmax = numpy.min(entry), numpy.max(entry)
30 ldiff = lmax - lmin
31 #entry = (entry - lmin) / ldiff
32 result[x:x + xres, y:y + yres] = entry
33 return result.T
34
35
36
37
38
39