title: How to select a region of an image in bokeh
body: <p>In a web app, I would like to let the user select a region of interest in a plotted image using the nice box/lasso selection tools of bokeh. I would the like to receive the selected pixels for further operations in python.</p>
  
  <p>For scatter plots, this is easy to do in analogy with the <a href="https://github.com/bokeh/bokeh/blob/master/examples/app/selection_histogram.py" rel="nofollow">gallery</a>,</p>
  
  <pre><code>import bokeh.plotting
  import numpy as np
  
  # data
  X = np.linspace(0, 10, 20)
  def f(x): return np.random.random(len(x))
  
  # plot and add to document
  fig = bokeh.plotting.figure(x_range=(0, 10), y_range=(0, 10),
      tools="pan,wheel_zoom,box_select,lasso_select,reset")
  plot = fig.scatter(X, f(X))
  #plot = fig.image([np.random.random((10,10))*255], dw=[10], dh=[10])
  bokeh.plotting.curdoc().add_root(fig)
  
  # callback
  def callback(attr, old, new):
      # easily access selected points:
      print sorted(new['1d']['indices'])
      print sorted(plot.data_source.selected['1d']['indices'])
      plot.data_source.data = {'x':X, 'y':f(X)}
  plot.data_source.on_change('selected', callback)
  </code></pre>
  
  <p>however if I replace the scatter plot with</p>
  
  <pre><code>plot = fig.image([np.random.random((10,10))*255], dw=[10], dh=[10])
  </code></pre>
  
  <p>then using the selection tools on the image does not change anything in <code>plot.data_source.selected</code>.</p>
  
  <p>I'm sure this is the intended behavior (and it makes sense too), but what if I want to select pixels of an image? I could of course put a grid of invisible scatter points on top of the image, but is there some more elegant way to accomplish this?</p>