comparison image_tools.py @ 436:d7ed780364b3

image_tools
author Olivier Breuleux <breuleuo@iro.umontreal.ca>
date Wed, 06 Aug 2008 19:39:14 -0400
parents
children
comparison
equal deleted inserted replaced
435:eac0a7d44ff0 436:d7ed780364b3
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