本文整理汇总了Python中pylab.imshow方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.imshow方法的具体用法?Python pylab.imshow怎么用?Python pylab.imshow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylab
的用法示例。
在下文中一共展示了pylab.imshow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def generate(self, filename, show=True):
'''Generate a sample sequence, plot the resulting piano-roll and save
it as a MIDI file.
filename : string
A MIDI file will be created at this location.
show : boolean
If True, a piano-roll of the generated sequence will be shown.'''
piano_roll = self.generate_function()
midiwrite(filename, piano_roll, self.r, self.dt)
if show:
extent = (0, self.dt * len(piano_roll)) + self.r
pylab.figure()
pylab.imshow(piano_roll.T, origin='lower', aspect='auto',
interpolation='nearest', cmap=pylab.cm.gray_r,
extent=extent)
pylab.xlabel('time (s)')
pylab.ylabel('MIDI note number')
pylab.title('generated piano-roll')
示例2: _plot_background
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def _plot_background(self, bgimage):
import pylab as pl
# Show the portion of the image behind this facade
left, right = self.facade_left, self.facade_right
top, bottom = 0, self.mega_facade.rectified.shape[0]
if bgimage is not None:
pl.imshow(bgimage[top:bottom, left:right], extent=(left, right, bottom, top))
else:
# Fit the facade in the plot
y0, y1 = pl.ylim()
x0, x1 = pl.xlim()
x0 = min(x0, left)
x1 = max(x1, right)
y0 = min(y0, top)
y1 = max(y1, bottom)
pl.xlim(x0, x1)
pl.ylim(y1, y0)
示例3: plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plot(self):
""" Plot the layer data (for debugging)
:return: The current figure
"""
import pylab as pl
aspect = self.nrows / float(self.ncols)
figure_width = 6 #inches
rows = max(1, int(np.sqrt(self.nlayers)))
cols = int(np.ceil(self.nlayers/rows))
# noinspection PyUnresolvedReferences
pallette = {i:rgb for (i, rgb) in enumerate(pl.cm.jet(np.linspace(0, 1, 4), bytes=True))}
f, a = pl.subplots(rows, cols)
f.set_size_inches(6 * cols, 6 * rows)
a = a.flatten()
for i, label in enumerate(self.label_names):
pl.sca(a[i])
pl.title(label)
pl.imshow(self.color_data)
pl.imshow(colorize(self.label_data[:, :, i], pallette), alpha=0.5)
# axis('off')
return f
示例4: plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plot(self, overlay_alpha=0.5):
import pylab as pl
rows = int(sqrt(self.layers()))
cols = int(ceil(self.layers()/rows))
for i in range(rows*cols):
pl.subplot(rows, cols, i+1)
pl.axis('off')
if i >= self.layers():
continue
pl.title('{}({})'.format(self.labels[i], i))
pl.imshow(self.image)
pl.imshow(colorize(self.features[i].argmax(0),
colors=np.array([[0, 0, 255],
[0, 255, 255],
[255, 255, 0],
[255, 0, 0]])),
alpha=overlay_alpha)
示例5: _extract_lines
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def _extract_lines(img, edges=None, mask=None, min_line_length=20, max_line_gap=3):
global __i__
__i__ += 1
if edges is None:
edges = canny(rgb2grey(img))
if mask is not None:
edges = edges & mask
# figure()
# subplot(131)
# imshow(img)
# subplot(132)
#vimshow(edges)
# subplot(133)
# if mask is not None:
# imshow(mask, cmap=cm.gray)
# savefig('/home/shared/Projects/Facades/src/data/for-labelme/debug/foo/{:06}.jpg'.format(__i__))
lines = np.array(probabilistic_hough_line(edges, line_length=min_line_length, line_gap=max_line_gap))
return lines
示例6: plot_rectified
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plot_rectified(self):
import pylab
pylab.title('rectified')
pylab.imshow(self.rectified)
for line in self.vlines:
p0, p1 = line
p0 = self.inv_transform(p0)
p1 = self.inv_transform(p1)
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='green')
for line in self.hlines:
p0, p1 = line
p0 = self.inv_transform(p0)
p1 = self.inv_transform(p1)
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='red')
pylab.axis('image');
pylab.grid(c='yellow', lw=1)
pylab.plt.yticks(np.arange(0, self.l, 100.0));
pylab.xlim(0, self.w)
pylab.ylim(self.l, 0)
示例7: compute_ffmc2d
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def compute_ffmc2d(X):
"""Computes the 2D-Fourier Magnitude Coefficients."""
# 2d-fft
fft2 = scipy.fftpack.fft2(X)
# Magnitude
fft2m = magnitude(fft2)
# FFTshift and flatten
fftshift = scipy.fftpack.fftshift(fft2m).flatten()
#cmap = plt.cm.get_cmap('hot')
#plt.imshow(np.log1p(scipy.fftpack.fftshift(fft2m)).T, interpolation="nearest",
# aspect="auto", cmap=cmap)
#plt.show()
# Take out redundant components
return fftshift[:fftshift.shape[0] // 2 + 1]
示例8: on_epoch_end
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def on_epoch_end(self, epoch, logs={}):
self.model.save_weights(os.path.join(self.output_dir, 'weights%02d.h5' % (epoch)))
self.show_edit_distance(256)
word_batch = next(self.text_img_gen)[0]
res = decode_batch(self.test_func, word_batch['the_input'][0:self.num_display_words])
if word_batch['the_input'][0].shape[0] < 256:
cols = 2
else:
cols = 1
for i in range(self.num_display_words):
pylab.subplot(self.num_display_words // cols, cols, i + 1)
if K.image_data_format() == 'channels_first':
the_input = word_batch['the_input'][i, 0, :, :]
else:
the_input = word_batch['the_input'][i, :, :, 0]
pylab.imshow(the_input.T, cmap='Greys_r')
pylab.xlabel('Truth = \'%s\'\nDecoded = \'%s\'' % (word_batch['source_str'][i], res[i]))
fig = pylab.gcf()
fig.set_size_inches(10, 13)
pylab.savefig(os.path.join(self.output_dir, 'e%02d.png' % (epoch)))
pylab.close()
示例9: plot_confusion_matrix
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plot_confusion_matrix(self, matrix, labels):
if not self.to_save and not self.to_show:
return
pylab.figure()
pylab.imshow(matrix, interpolation='nearest', cmap=pylab.cm.jet)
pylab.title("Confusion Matrix")
for i, vi in enumerate(matrix):
for j, vj in enumerate(vi):
pylab.annotate("%.1f" % vj, xy=(j, i), horizontalalignment='center', verticalalignment='center', fontsize=9)
pylab.colorbar()
classes = np.arange(len(labels))
pylab.xticks(classes, labels)
pylab.yticks(classes, labels)
pylab.ylabel('Expected label')
pylab.xlabel('Predicted label')
示例10: plotFields
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plotFields(layer,fieldShape=None,channel=None,figOffset=1,cmap=None,padding=0.01):
# Receptive Fields Summary
try:
W = layer.W
except:
W = layer
wp = W.eval().transpose();
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
fields = np.reshape(wp,list(wp.shape[0:-1])+fieldShape)
else: # Convolutional layer already has shape
features, channels, iy, ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fig = mpl.figure(figOffset); mpl.clf()
# Using image grid
from mpl_toolkits.axes_grid1 import ImageGrid
grid = ImageGrid(fig,111,nrows_ncols=(perRow,perColumn),axes_pad=padding,cbar_mode='single')
for i in range(0,np.shape(fields)[0]):
im = grid[i].imshow(fields[i],cmap=cmap);
grid.cbar_axes[0].colorbar(im)
mpl.title('%s Receptive Fields' % layer.name)
# old way
# fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
# tiled = []
# for i in range(0,perColumn*perRow,perColumn):
# tiled.append(np.hstack(fields2[i:i+perColumn]))
#
# tiled = np.vstack(tiled)
# mpl.figure(figOffset); mpl.clf(); mpl.imshow(tiled,cmap=cmap); mpl.title('%s Receptive Fields' % layer.name); mpl.colorbar();
mpl.figure(figOffset+1); mpl.clf(); mpl.imshow(np.sum(np.abs(fields),0),cmap=cmap); mpl.title('%s Total Absolute Input Dependency' % layer.name); mpl.colorbar()
示例11: plotOutput
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plotOutput(layer,feed_dict,fieldShape=None,channel=None,figOffset=1,cmap=None):
# Output summary
try:
W = layer.output
except:
W = layer
wp = W.eval(feed_dict=feed_dict);
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
temp = np.zeros(np.product(fieldShape)); temp[0:np.shape(wp.ravel())[0]] = wp.ravel()
fields = np.reshape(temp,[1]+fieldShape)
else: # Convolutional layer already has shape
wp = np.rollaxis(wp,3,0)
features, channels, iy,ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
tiled = []
for i in range(0,perColumn*perRow,perColumn):
tiled.append(np.hstack(fields2[i:i+perColumn]))
tiled = np.vstack(tiled)
if figOffset is not None:
mpl.figure(figOffset); mpl.clf();
mpl.imshow(tiled,cmap=cmap); mpl.title('%s Output' % layer.name); mpl.colorbar();
示例12: plotFields
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plotFields(layer,fieldShape=None,channel=None,maxFields=25,figName='ReceptiveFields',cmap=None,padding=0.01):
# Receptive Fields Summary
W = layer.W
wp = W.eval().transpose();
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
fields = np.reshape(wp,list(wp.shape[0:-1])+fieldShape)
else: # Convolutional layer already has shape
features, channels, iy, ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
fieldsN = min(fields.shape[0],maxFields)
perRow = int(math.floor(math.sqrt(fieldsN)))
perColumn = int(math.ceil(fieldsN/float(perRow)))
fig = mpl.figure(figName); mpl.clf()
# Using image grid
from mpl_toolkits.axes_grid1 import ImageGrid
grid = ImageGrid(fig,111,nrows_ncols=(perRow,perColumn),axes_pad=padding,cbar_mode='single')
for i in range(0,fieldsN):
im = grid[i].imshow(fields[i],cmap=cmap);
grid.cbar_axes[0].colorbar(im)
mpl.title('%s Receptive Fields' % layer.name)
# old way
# fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
# tiled = []
# for i in range(0,perColumn*perRow,perColumn):
# tiled.append(np.hstack(fields2[i:i+perColumn]))
#
# tiled = np.vstack(tiled)
# mpl.figure(figOffset); mpl.clf(); mpl.imshow(tiled,cmap=cmap); mpl.title('%s Receptive Fields' % layer.name); mpl.colorbar();
mpl.figure(figName+' Total'); mpl.clf(); mpl.imshow(np.sum(np.abs(fields),0),cmap=cmap); mpl.title('%s Total Absolute Input Dependency' % layer.name); mpl.colorbar()
示例13: plotOutput
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plotOutput(layer,feed_dict,fieldShape=None,channel=None,figOffset=1,cmap=None):
# Output summary
W = layer.output
wp = W.eval(feed_dict=feed_dict);
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
temp = np.zeros(np.product(fieldShape)); temp[0:np.shape(wp.ravel())[0]] = wp.ravel()
fields = np.reshape(temp,[1]+fieldShape)
else: # Convolutional layer already has shape
wp = np.rollaxis(wp,3,0)
features, channels, iy,ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
tiled = []
for i in range(0,perColumn*perRow,perColumn):
tiled.append(np.hstack(fields2[i:i+perColumn]))
tiled = np.vstack(tiled)
if figOffset is not None:
mpl.figure(figOffset); mpl.clf();
mpl.imshow(tiled,cmap=cmap); mpl.title('%s Output' % layer.name); mpl.colorbar();
示例14: explorer
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def explorer():
for c in range(0, len(captchas), 77):
e = del_line(captchas[c])
pl.figure(c)
for i, p in enumerate(split_pic(e)):
pl.subplot(221+i)
char = e[:, p[0]:p[1]]
y1, y2 = split_y(char)
pl.imshow(regularize(char[y1:y2, :]), cmap=pl.cm.Greys)
pl.show()
if raw_input() == 'q':
pl.close('all')
break
示例15: plotMagnitudeSpectrogram
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import imshow [as 别名]
def plotMagnitudeSpectrogram(self, rate, sample, framesz, hop):
"""
Calculates and plots the magnitude spectrum of a given sound wave.
"""
X = self.STFT(sample, rate, framesz, hop)
# Plot the magnitude spectrogram.
pylab.figure('Magnitude spectrogram')
pylab.imshow(scipy.absolute(X.T), origin='lower', aspect='auto',
interpolation='nearest')
pylab.xlabel('Time')
pylab.ylabel('Frequency')
pylab.show()