Advertisement
luistavares

Exemplo de Aplicação Interativa no Jupyter Notebook

Mar 19th, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # imports
  2. %matplotlib inline
  3. import matplotlib.pyplot as plt
  4. import networkx as nx
  5. from ipywidgets import interact
  6. import matplotlib.image as mpimg
  7. import numpy as np
  8.  
  9. # functions
  10. def get_image():
  11.     f = mpimg.imread('images/Lenna.png')
  12.     f = (f[:,:,0] + f[:,:,1] + f[:,:,2]) / 3
  13.     return f
  14.  
  15. def show_image(sample_factor, rep_factor):
  16.     plt.figure()
  17.     f = get_image()
  18.     f = f[::sample_factor, ::sample_factor]
  19.     f = np.tile(f, (rep_factor,rep_factor))
  20.     imgplot = plt.imshow(f, cmap='Greys_r', interpolation='none')
  21.     plt.show()
  22.  
  23. interact(show_image, sample_factor=(2,50), rep_factor=(1,10));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement