def vis_square(self, data):
"""Take an array of shape (n, height, width) or (n, height, width, 3)
and visualize each (height, width) thing in a grid of size approx. sqrt(n) by sqrt(n)"""
print "Data Shape : ", data.shape
# normalize data for display
data = (data - data.min()) / (data.max() - data.min())
# force the number of filters to be square
n = int(np.ceil(np.sqrt(data.shape[0])))
padding = (((0, n ** 2 - data.shape[0]),
(0, 1), (0, 1)) # add some space between filters
+ ((0, 0),) * (data.ndim - 3)) # don't pad the last dimension (if there is one)
data = np.pad(data, padding, mode='constant', constant_values=0) # pad with ones (white)
# tile the filters into an image
data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
# show at display
#print 'Data shape : ', data.shape , len(data.shape)
img = 255 * data
img = cv2.resize(img, (512, 512))
img = np.array(img, dtype='uint8')
img_c = cv2.applyColorMap(img, cv2.COLORMAP_JET)
height, width, byteValue = img_c.shape
byteValue = byteValue * width
self.image = QtGui.QImage(img_c.data, width, height, byteValue, QtGui.QImage.Format_RGB888)
self.ui.labelDisplay.setPixmap(QtGui.QPixmap(self.image))
评论列表
文章目录