import logging
import numpy as np
import matplotlib.pyplot as plt
import skimage.future
import fibsem.conversions
log = logging.getLogger(__name__)
def _manual_lasso_roi(image):
"""User draws a polygon region of interest interactively."""
image = fibsem.conversions._convert_to_numpy(image)
mask = skimage.future.manual_lasso_segmentation(image)
return mask
def _manual_polygon_roi(image):
"""User draws a polygon region of interest interactively."""
image = fibsem.conversions._convert_to_numpy(image)
mask = skimage.future.manual_polygon_segmentation(image)
return mask
[docs]def manual_segmentation(image):
"""Interactively let the user select the region for ion milling.
Parameters
----------
image : Ion beam image of sample
Returns
-------
milling_region : 2D boolean numpy array, True where milling should occur.
"""
log.info("Draw a polygon around the area you want to mill. \n"
"Right click to complete the polygon shape, "
"then close the window, or press the undo button to redraw.")
milling_region = _manual_polygon_roi(image)
return milling_region.astype(np.bool)
[docs]def select_point(image):
"""Return location of interactive user click on image.
Parameters
----------
image : AdornedImage or 2D numpy array.
Returns
-------
coords
Coordinates of last point clicked in the image.
Coordinates are in row, column format.
Units are the same as the matplotlib figure axes.
"""
fig, ax = fibsem.display.quick_plot(image)
coords = []
def on_click(event):
print(event.ydata, event.xdata)
coords.append(event.ydata)
coords.append(event.xdata)
fig.canvas.mpl_connect('button_press_event', on_click)
plt.show()
return tuple(coords)