
Hi,
I’m trying to get the coordinates of all the pixels inside an area of interest using the Lasso select tool from an numpy array image.
A sample code is below. How can I extract the coordinates of all the pixels that have been selected by the lasso tool? Is using a customJS the right way? If so, what data should I extract with the javascript? Thanks for any help!
from bokeh.server.server import Server
from bokeh.models import LassoSelectTool
from bokeh.plotting import figure
from bokeh.io import show
from bokeh.layouts import column
import numpy as np
from functools import partial
def make_document(doc, mask, img):
def update(attr, old, new):
print('something selected.')
fig = figure(tools=[LassoSelectTool()])
fig.select(LassoSelectTool).select_every_mousemove = False
r = fig.image([img], 0, 0 ,1,1)
r.data_source.selected.on_change('data', update)
doc.add_root(column([fig]))
if __name__ == '__main__':
image = np.random.rand(512, 512)
server = Server({'/': partial(make_document, mask=image, img=image)})
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()