# HG changeset patch # User Olivier Breuleux # Date 1218065954 14400 # Node ID d7ed780364b3e2f99172eabecd78899738b279c8 # Parent eac0a7d44ff075bc31ed483eaf4681512ee37963 image_tools diff -r eac0a7d44ff0 -r d7ed780364b3 image_tools.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/image_tools.py Wed Aug 06 19:39:14 2008 -0400 @@ -0,0 +1,39 @@ + +import numpy + + +def make_weights_image(mat, xres, yres, i, j, nrow, ncol): + """ + Displays the filters implemented by a weight matrix. + + Each filter corresponds to a row of mat and will be represented + by a xres*yres image. + + Units from i to j will be included in the picture. + + The picture will have nrow rows of filters and ncol columns + of filters. Unused spots for filters will be filled with zeros. + + The return value is a matrix suitable for display with + matplotlib's imshow. + """ + + assert j > i + n = j - i + result = numpy.zeros((ncol * xres, nrow * yres)) + submat = mat[i:j] + for k, row in enumerate(submat): + x = (k % ncol)*xres + y = (k / ncol)*yres + entry = row.reshape((xres, yres)) + lmin, lmax = numpy.min(entry), numpy.max(entry) + ldiff = lmax - lmin + #entry = (entry - lmin) / ldiff + result[x:x + xres, y:y + yres] = entry + return result.T + + + + + +