#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_cell_magic('javascript', '', "$.getScript('../ipython_notebook_toc.js');\n") # In[2]: get_ipython().run_line_magic('matplotlib', 'inline') import sys sys.path.insert(0,'..') from IPython.display import HTML from helpers import header HTML(header()) # Exercices and practical works # ============================= # Most of the samples given in this course use python and numpy package, an example is given below where the gray level histogram is computed for an image using standard `histogram` numpy function. # In[3]: get_ipython().run_line_magic('matplotlib', 'inline') import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from skimage.data import camera plt.style.use('ggplot') plt.figure(figsize=[10,5]) ima = camera() #use a test image provided by the skimage library hist,bins = np.histogram(ima.flatten(),range(256)) # histogram is computed on a 1D distribution --> flatten() norm_hist = 1.*hist/np.sum(hist) # normalized histogram # display the results plt.subplot(1,2,1) plt.imshow(camera(),cmap=cm.gray) plt.subplot(1,2,2) plt.plot(norm_hist) plt.xlabel('gray level');