• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyplot.gray函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.pyplot.gray函数的典型用法代码示例。如果您正苦于以下问题:Python gray函数的具体用法?Python gray怎么用?Python gray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了gray函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:ErwanGalline,项目名称:test,代码行数:28,代码来源:util2.py


示例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')
开发者ID:likeMyCode,项目名称:HCInteraction,代码行数:29,代码来源:find_planes.py


示例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)
开发者ID:Nyker510,项目名称:Chainer,代码行数:30,代码来源:save_mnist_digit_fig.py


示例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()
开发者ID:klangner,项目名称:license_plate,代码行数:7,代码来源:helpers.py


示例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()
开发者ID:willianfatec,项目名称:PatchWiser,代码行数:35,代码来源:binarypattern.py


示例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()
开发者ID:jstol,项目名称:road-estimation,代码行数:31,代码来源:markovrandomfield_bishop.py


示例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()
开发者ID:juho-lee,项目名称:tf_practice,代码行数:30,代码来源:mnist_svae_attn.py


示例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()
开发者ID:juho-lee,项目名称:tf_practice,代码行数:31,代码来源:mnist_ssdgm.py


示例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()
开发者ID:cowpig,项目名称:facial_keypoints,代码行数:7,代码来源:facial_keypoints.py


示例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)
开发者ID:StevenReitsma,项目名称:kaggle-diabetic-retinopathy,代码行数:7,代码来源:util.py


示例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()
开发者ID:MarkPrecursor,项目名称:Programming-Computer-Vision-with-python,代码行数:7,代码来源:Harris.py


示例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()
开发者ID:jschleic,项目名称:simple-STORM,代码行数:27,代码来源:plotDataAndCoords.py


示例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')
开发者ID:ky822,项目名称:assignment7,代码行数:30,代码来源:A7_Question4.py


示例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()
开发者ID:omidi,项目名称:CellLineageTracking,代码行数:31,代码来源:slic.py


示例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)
                            ))
                  )
开发者ID:Neil-G,项目名称:Facial-Reconstruction,代码行数:27,代码来源:FacialRecon.py


示例16: save_image

def save_image(img, fn):
	if len(img) == 96*96:
		plt.imshow(to_matrix(img))
	else:
		plt.imshow(img)
	plt.gray()
	plt.savefig(fn)
开发者ID:cowpig,项目名称:facial_keypoints,代码行数:7,代码来源:facial_keypoints.py


示例17: visualize_world

    def visualize_world(self, brain):
        """ 
        Show what's going on in the world.
        """
        if self.print_features:
            projections, activities = brain.cortex.get_index_projections(to_screen=True)
            wtools.print_pixel_array_features(
                    projections, 
                    self.fov_span ** 2 * 2, 
                    0,#self.num_actions,
                    self.fov_span, self.fov_span, 
                    world_name=self.name)

        # Periodically show the state history and inputs as perceived by BECCA
        print ''.join(["world is ", str(self.timestep), " timesteps old"])
        fig = plt.figure(11)
        plt.clf()
        plt.plot( self.column_history, 'k.')    
        plt.title(''.join(['Column history for ', self.name]))
        plt.xlabel('time step')
        plt.ylabel('position (pixels)')
        fig.show()
        fig.canvas.draw()

        fig  = plt.figure(12)
        sensed_image = np.reshape(
                0.5 * (self.sensors[:len(self.sensors)/2] - 
                       self.sensors[len(self.sensors)/2:] + 1), 
                (self.fov_span, self.fov_span))
        plt.gray()
        plt.imshow(sensed_image, interpolation='nearest')
        plt.title("Image sensed")
        fig.show()
        fig.canvas.draw()
开发者ID:btapo,项目名称:becca,代码行数:34,代码来源:image_1D.py


示例18: plot_raw

def plot_raw(data, spectrum=None):
    """This function plots image data and spectrum. If the spectrum is not
    given, it is computed from the image data."""
    if spectrum==None:
        spectrum = spectrum_from_raw(data)

    plot.figure()
    plot.title("Raw data with summation lines")
    plot.imshow(data)
    plot.gray()
    X = np.linspace(0,data.shape[1],1000)
    b = CURVE_B
    A = np.linspace(CURVE_A_MIN, CURVE_A_MAX, data.shape[0])
    for y in xrange(0, data.shape[0], 50):
        a = A[y]
        Y = a*(X-b)**2 + y
        plot.plot(X,Y.round(),color="white")
    plot.xlim(0,data.shape[1])
    plot.ylim(0,data.shape[0])
    plot.axvline(SLIT_DIVISION)
    
    plot.figure()
    plot.title("Spectrum normalized to 550nm")
    plot.xlabel("Wavelength (nm)")
    plot.ylabel("Normalized intensity")
    X = np.arange(len(spectrum))
    X = calibration(X)
    plot.plot(X,spectrum[:,0], "-", linewidth=2, color="black", label="Wide slit")
    plot.plot(X,spectrum[:,1], ":", linewidth=2, color="black", label="Narrow slit")
    plot.xlim(X.min(), X.max())
    plot.legend()
#    plot.axvline(435.8)
#    plot.axvline(611.6)
#    plot.axvline(487)
    plot.show()
开发者ID:dronir,项目名称:iSpex-python,代码行数:35,代码来源:iSpex_spectrum.py


示例19: q4

def q4():
  '''question #4 module'''
  #grids
  pixel=1000.0
  x=np.arange(-2,1,3.0/pixel)
  y=np.arange(-1.5,1.5,3.0/pixel)
  xs,ys=np.meshgrid(x,y)

  #intialize
  mask=np.empty((pixel,pixel))
  mask[:,:]=1
  max_N=50
  bound=50
  c=xs+(1j*ys)
  z=c

  for t in np.arange(max_N):
    z= z**2 + c
    mask=mask*(z<bound)

  import matplotlib.pyplot as plt
  plt.imshow(mask, extent=[-2, 1, -1.5, 1.5])
  plt.gray()
  plt.savefig('mandelbrot.png')
  print ""
  print "Question #4"
  print "mandelbrot.png has been saved to local directory"
  print ""
开发者ID:im965,项目名称:assignment7,代码行数:28,代码来源:assignment7.py


示例20: compute_mandelbrot

def compute_mandelbrot():
	N_max = 50
	some_threshold = 50

	grid_interval = 1000

	# construct the grid 
	x = np.linspace(-2, 1, grid_interval)
	y = np.linspace(-1.5, 1.5, grid_interval)

	c = x[:, np.newaxis] + 1j*y[np.newaxis, :]

	# do the iteration 
	z = c 
	for v in range(N_max):
		with np.errstate(all = "ignore"): # catches overflow and invalid value errors 
			z = z**2 + c 
		
	with np.errstate(all = "ignore"): # catches overflow and invalid value errors 

		# form a 2-D boolean mask 
		mask = (abs(z) < some_threshold)

	# save the result to an image
	plt.imshow(mask.T, extent = [-2, 1, -1.5, 1.5])
	plt.gray()
	plt.savefig('mandelbrot.png')
开发者ID:ShixinLi,项目名称:assignment7,代码行数:27,代码来源:Mandelbrot.py



注:本文中的matplotlib.pyplot.gray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyplot.grid函数代码示例发布时间:2022-05-27
下一篇:
Python pyplot.ginput函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap