annotate image_tools.py @ 530:844bad76459c

replaced the use of removed function compile.eval_outputs with theano.function.
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 17 Nov 2008 14:18:28 -0500
parents d7ed780364b3
children
rev   line source
436
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
1
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
2 import numpy
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
3
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
4
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
5 def make_weights_image(mat, xres, yres, i, j, nrow, ncol):
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
6 """
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
7 Displays the filters implemented by a weight matrix.
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
8
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
9 Each filter corresponds to a row of mat and will be represented
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
10 by a xres*yres image.
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
11
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
12 Units from i to j will be included in the picture.
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
13
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
14 The picture will have nrow rows of filters and ncol columns
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
15 of filters. Unused spots for filters will be filled with zeros.
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
16
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
17 The return value is a matrix suitable for display with
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
18 matplotlib's imshow.
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
19 """
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
20
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
21 assert j > i
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
22 n = j - i
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
23 result = numpy.zeros((ncol * xres, nrow * yres))
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
24 submat = mat[i:j]
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
25 for k, row in enumerate(submat):
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
26 x = (k % ncol)*xres
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
27 y = (k / ncol)*yres
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
28 entry = row.reshape((xres, yres))
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
29 lmin, lmax = numpy.min(entry), numpy.max(entry)
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
30 ldiff = lmax - lmin
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
31 #entry = (entry - lmin) / ldiff
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
32 result[x:x + xres, y:y + yres] = entry
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
33 return result.T
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
34
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
35
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
36
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
37
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
38
d7ed780364b3 image_tools
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents:
diff changeset
39