本文整理汇总了Python中matplotlib.pyplot.gray函数的典型用法代码示例。如果您正苦于以下问题:Python gray函数的具体用法?Python gray怎么用?Python gray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: graph_spectrogram
def graph_spectrogram(wav_file, wav_folder):
name_save = wav_file.replace(".wav", ".png")
name_save_cv2 = wav_file.replace(".wav", "_cv2.png")
rate, data = get_wav_info(wav_file)
nfft = 256 # Length of the windowing segments
fs = 256 # Sampling frequency
plt.clf()
pxx, freqs, bins, im = plt.specgram(data, nfft, fs)
plt.axis('off')
plt.gray()
plt.savefig(name_save,
dpi=50, # Dots per inch
frameon='false',
aspect='normal',
bbox_inches='tight',
pad_inches=0)
# Expore plote as image
fig = plt.gcf()
fig.canvas.draw()
# Get the RGBA buffer from the figure
w, h = fig.canvas.get_width_height()
buf = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8)
buf.shape = (w, h, 3)
# canvas.tostring_argb give pixmap in ARGB mode. Roll the ALPHA channel to have it in RGBA mode
# buf = np.roll(buf, 2)
cv2.imwrite(name_save_cv2, buf)
示例2: just_do_it
def just_do_it(limit_cont):
fig = plt.figure(facecolor='black')
plt.gray()
print("Rozpoczynam przetwarzanie obrazow...")
for i in range(20):
img = data.imread(images[i])
gray_img = to_gray(images[i]) # samoloty1.pdf
#gray_img = to_gray2(images[i], 1001, 0.2, 5, 9, 12) # samoloty2.pdf
#gray_img = to_gray2(images[i], 641, 0.2, 5, 20, 5) # samoloty3.pdf
conts = find_contours(gray_img, limit_cont)
centrs = [find_centroid(cont) for cont in conts]
ax = fig.add_subplot(4,5,i)
ax.set_yticks([])
ax.set_xticks([])
io.imshow(img)
print("Przetworzono: " + images[i])
for n, cont in enumerate(conts):
ax.plot(cont[:, 1], cont[:, 0], linewidth=2)
for centr in centrs:
ax.add_artist(plt.Circle(centr, 5, color='white'))
fig.tight_layout()
#plt.show()
plt.savefig('samoloty3.pdf')
示例3: plot_images
def plot_images(data_list, data_shape="auto", fig_shape="auto"):
"""
plotting data on current plt object.
In default,data_shape and fig_shape are auto.
It means considered the data as a sqare structure.
"""
n_data = len(data_list)
if data_shape == "auto":
sqr = int(n_data ** 0.5)
if sqr * sqr != n_data:
data_shape = (sqr + 1, sqr + 1)
else:
data_shape = (sqr, sqr)
plt.figure(figsize=data_shape)
for i, data in enumerate(data_list):
plt.subplot(data_shape[0], data_shape[1], i + 1)
plt.gray()
if fig_shape == "auto":
fig_size = int(len(data) ** 0.5)
if fig_size ** 2 != len(data):
fig_shape = (fig_size + 1, fig_size + 1)
else:
fig_shape = (fig_size, fig_size)
Z = data.reshape(fig_shape[0], fig_shape[1])
plt.imshow(Z, interpolation="nearest")
plt.tick_params(labelleft="off", labelbottom="off")
plt.tick_params(axis="both", which="both", left="off", bottom="off", right="off", top="off")
plt.subplots_adjust(hspace=0.05)
plt.subplots_adjust(wspace=0.05)
示例4: plot_images
def plot_images(images, labels):
fig = plt.figure()
plt.gray()
for i in range(min(9, images.shape[0])):
fig.add_subplot(3, 3, i+1)
show_image(images[i], labels[i])
plt.show()
示例5: mostra_imagens
def mostra_imagens(imagens, tam_patch=64):
"""Display a list of images"""
n_imgs = len(imagens)
fig = plt.figure()
n = 1
for img in imagens:
imagem = img[0]
titulo = img[1]
#####################################
v, h, _ = imagem.shape
# calcula as bordas horizontais
h_m1 = h % tam_patch
h_m2 = h_m1//2
h_m1 -= h_m2
# calcula das bordas verticais
v_m1 = v % tam_patch
v_m2 = v_m1//2
v_m1 -= v_m2
#####################################
a = fig.add_subplot(1,n_imgs,n)
a.set_xticks(np.arange(0+h_m1, 700-h_m2, tam_patch))
a.set_yticks(np.arange(0+v_m1, 460-v_m2, tam_patch))
a.grid(True)
if imagem.ndim == 2:
plt.gray()
plt.imshow(imagem)
a.set_title(titulo)
n += 1
fig.set_size_inches(np.array(fig.get_size_inches()) * n_imgs)
plt.show()
示例6: run_denoising
def run_denoising():
noisy = prediction_image
fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
plt.gray()
ax[0, 0].imshow(noisy)
ax[0, 0].axis('off')
ax[0, 0].set_title('noisy')
ax[0, 1].imshow(denoise_tv_chambolle(noisy, weight=0.1, multichannel=True))
ax[0, 1].axis('off')
ax[0, 1].set_title('TV')
ax[0, 2].imshow(denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15))
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')
ax[1, 0].imshow(denoise_tv_chambolle(noisy, weight=0.2, multichannel=True))
ax[1, 0].axis('off')
ax[1, 0].set_title('(more) TV')
ax[1, 1].imshow(denoise_bilateral(noisy, sigma_range=0.1, sigma_spatial=15))
ax[1, 1].axis('off')
ax[1, 1].set_title('(more) Bilateral')
ax[1, 2].imshow(noisy)
ax[1, 2].axis('off')
ax[1, 2].set_title('original')
fig.subplots_adjust(wspace=0.02, hspace=0.2,
top=0.9, bottom=0.05, left=0, right=1)
plt.show()
示例7: test
def test():
saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
batch_x, _ = mnist.test.next_batch(10)
batch_x_att, batch_p = sess.run([x_att, p], {x:batch_x})
A = np.zeros((0, N*N))
for i in range(10):
for k in range(K):
A = np.concatenate([A, batch_x_att[k][i].reshape((1, N*N))], 0)
fig = plt.figure('attended')
plt.gray()
plt.axis('off')
plt.imshow(batchmat_to_tileimg(A, (N, N), (10, K)))
fig.savefig(FLAGS.save_dir+'/attended.png')
"""
P = np.zeros((0, n_in))
for i in range(10):
P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
for k in range(K):
P = np.concatenate([P, batch_pk[k][i].reshape((1, n_in))], 0)
P = np.concatenate([P, batch_p[i].reshape((1, n_in))])
fig = plt.figure('reconstructed')
plt.gray()
plt.axis('off')
plt.imshow(batchmat_to_tileimg(P, (height, width), (10, K+2)))
fig.savefig(FLAGS.save_dir+'/reconstructed.png')
"""
plt.show()
示例8: test
def test():
saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
batch_x, batch_y = mnist.test.next_batch(100)
"""
fig = plt.figure('original')
plt.gray()
plt.axis('off')
plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
fig.savefig(FLAGS.save_dir+'/original.png')
fig = plt.figure('reconstructed')
plt.gray()
plt.axis('off')
p_recon = sess.run(p_x, {x:batch_x, y:batch_y})
plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
fig.savefig(FLAGS.save_dir+'/reconstructed.png')
"""
batch_z = np.random.normal(size=(100, 50))
batch_y = np.zeros((100, 10))
for i in range(10):
batch_y[i*10:(i+1)*10, i] = 1.0
fig = plt.figure('generated')
plt.gray()
plt.axis('off')
p_gen = sess.run(p_x, {z:batch_z, y:batch_y, is_train:False})
plt.imshow(batchmat_to_tileimg(p_gen, (height, width), (10, 10)))
fig.savefig(FLAGS.save_dir+'/generated.png')
plt.show()
示例9: display_image
def display_image(img):
if len(img) == 96*96:
plt.imshow(to_matrix(img))
else:
plt.imshow(img)
plt.gray()
plt.show()
示例10: plot
def plot(image, invert = False, cmap=plt.cm.binary):
if invert:
image = np.ones(len(image)) - image
plt.gray()
plt.imshow(image, cmap=cmap)
示例11: Plot_harris_points
def Plot_harris_points(img, filtered_coords):
plt.figure()
plt.gray()
plt.imshow(img)
plt.plot([p[1] for p in filtered_coords], [p[0] for p in filtered_coords], '.')
plt.axis('off')
plt.show()
示例12: pltImAndCoords
def pltImAndCoords(h5file, frame, coordFiles, printerFriendly=True):
'''read image coordinates, plot them together with the raw data
save output as .png or .tiff or display with matplotlib'''
# read input data
rawData = h5.readHDF5Frame(h5file, frame)
coordDat = [(coord2im.readCoordsFile(f)) for f in coordFiles]
if printerFriendly:
rawData = -rawData
plt.imshow(rawData, interpolation='nearest')
plt.colorbar()
plt.gray()
axx = plt.axis()
markers = ['r+', 'bx', 'go', 'k,', 'co', 'yo']
for i in range(len(coordFiles)):
c, w, h = coordDat[i]
cc = np.array(c)
idxs = (cc[:,2] == frame)
cc = cc[idxs]
ll = coordFiles[i][coordFiles[i].rfind('/')+1:]
plt.plot(cc[:,0], cc[:,1], markers[i], label=ll)
plt.legend()
plt.axis(axx) # dont change axis by plotting coordinates
plt.show()
示例13: Mandelbrot
def Mandelbrot(rows= 1000, cols = 1000):
print " **** Question 4 ****"
print "Please wait patiently while the calculation is underway."
#initialize grid and params
threshold = 50
N_max = 50
x = np.linspace(-2,1,cols)
y = np.linspace(-1.5, 1.5,rows)
mask = np.ones((rows,cols))
x_elements, y_elements = np.meshgrid(x,y)
C = x_elements + 1j*y_elements
#initialize
Z = C
# ignore runtime\overflow error. we can do this since we do not care about about the actual entries of z besides diverging\not diverging.
np.seterr(all='ignore')
# loop and change mask.
for v in range(N_max):
Z = Z**2 + C
mask = mask*(np.abs(Z)<threshold)
plt.imshow(mask, extent=[-2, 1, -1.5, 1.5])
plt.gray()
plt.savefig('mandelbrot.png')
示例14: denoising
def denoising(astro):
noisy = astro + 0.6 * astro.std() * np.random.random(astro.shape)
noisy = np.clip(noisy, 0, 1)
fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5), sharex=True,
sharey=True, subplot_kw={'adjustable': 'box-forced'})
plt.gray()
ax[0, 0].imshow(noisy)
ax[0, 0].axis('off')
ax[0, 0].set_title('noisy')
ax[0, 1].imshow(denoise_tv_chambolle(noisy, weight=0.1, multichannel=True))
ax[0, 1].axis('off')
ax[0, 1].set_title('TV')
ax[0, 2].imshow(denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15))
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')
ax[1, 0].imshow(denoise_tv_chambolle(noisy, weight=0.2, multichannel=True))
ax[1, 0].axis('off')
ax[1, 0].set_title('(more) TV')
ax[1, 1].imshow(denoise_bilateral(noisy, sigma_range=0.1, sigma_spatial=15))
ax[1, 1].axis('off')
ax[1, 1].set_title('(more) Bilateral')
ax[1, 2].imshow(astro)
ax[1, 2].axis('off')
ax[1, 2].set_title('original')
fig.tight_layout()
plt.show()
示例15: view
def view(stack, image): # function to view an image
''' View a single image from a chosen stack of images
Keyword arguments:
stack -- (str) this should be either 'train', 'test', or 'recon'
number -- (int) this is the index number of the image the stack,
12,000 images in the training set, 1233 in test set
'''
plt.gray()
if stack == 'train':
plt.imshow(np.hstack((
left[image].reshape(64,32),
right[image].reshape(64,32)
))
)
elif stack == 'test':
plt.imshow(test[image].reshape(64,32))
elif stack == 'recon':
plt.imshow(np.hstack((
test[image].reshape(64,32),
reconstructed[image].reshape(64,32)
))
)