GUIs for the Jupyter notebook#
The sdt.nbui
module contains graphical user interfaces to be used
within Jupyter notebooks.
Currently, there is
the
Locator
class for setting the parameters for thesdt.loc
algorithms with visual feedbackthe
Thresholder
class for setting parameters for the thresholding algorithms insdt.image
with visual feedbackthe
ROISelector
class for choosing ROIs by drawing them on imagesthe
FileDialog
class for selecting filesthe
ImageDisplay
class for displaying imagesthe
ChannelSplitter
class for separating multiple channels recorded using the same camera.
Programming reference#
- class sdt.nbui.Locator(**kwargs)[source]#
Notebook UI for finding parameters for single molecule localizations
This allows for loading single molecule image data, setting localization algorithm parameters and inspecting the result.
This requires the use of the widget (ipympl) matplotlib backend.
Note that this is still experimental and may be subject to change.
Examples
The first line in each notebook should enable the correct backend.
>>> %matplotlib widget
In a notebook cell, create the UI:
>>> locator = nbui.Locator()
Set image data to localize and display the UI
>>> locator.input = img_array # assuming this is an array of pixels >>> locator
or create use the built-in ImageSelector to go through multiple files
>>> files = sorted(pathlib.Path().glob("*.tif")) >>> locator.images = files
Now one can play around with the parameters. Once a satisfactory combination has been found, get the parameters in another notebook cell:
>>> locator.algorithm "3D-DAOSTORM" >>> par = locator.options >>> par {'radius': 1.0, 'model': '2d', 'threshold': 800.0, 'find_filter': 'Cg', 'find_filter_opts': {'feature_radius': 3}, 'min_distance': None, 'size_range': None}
**par
can be passed directly tolocate_func
andbatch_func
:>>> data = locator.batch_func(img_files, **par) # loc.daostorm_3d.batch
- Parameters:
cmap (str) – Colormap to use for displaying images.
- images: Dict | List | None#
Image files/sequences passed to the built-in
ImageSelector
. If empty or None, the selector is hidden. Using the selector to choose a frame setsinput
accordingly.
- input: ndarray | None#
Image data
- image_display: ImageDisplay#
Image display widget
- algorithm#
Name of the algorithm
- options#
dict of options to the localizing function
- property locate_func#
Currently selected single frame localization function
- property batch_func#
Currently selected batch localization function
- property locate_roi_func#
Currently selected single frame localization (+ ROI) function
- property batch_roi_func#
Currently selected batch localization (+ ROI) function
- class sdt.nbui.Thresholder(**kwargs)[source]#
Notebook UI for finding image thresholding parameters
This allows for loading image data, setting thresholding algorithm parameters and inspecting the result.
This requires the use of the widget (ipympl) matplotlib backend.
Examples
The first line in each notebook should enable the correct backend.
>>> %matplotlib widget
In a notebook cell, create the UI:
>>> # Assume img_list is a list of 2D arrays containing image data >>> th = Thresholder(img_list) >>> th
Now one can play around with the parameters. Once a satisfactory combination has been found, get the parameters in another notebook cell:
>>> th.algorithm "adaptive" >>> par = th.options >>> par {'block_size': 65, 'c': -5.0, 'smooth': 1.5, 'method': 'mean'}
**par
can be passed directly tofunc
>>> mask = th.func(img_list[0], **par) # image.adaptive_thresh
- Parameters:
images (Sequence | Dict) – List of image (sequences) to populate to pass to
ImageSelector
instance.
- algorithm: str#
Name of the algorithm
- options: Dict#
Options to the thresholding function
- property func: Callable#
Processing function of the currently selected algorithm
- class sdt.nbui.ROISelector(**kwargs)[source]#
Notebook UI for creating ROIs by drawing them on images
This is useful e.g. to select the region occupied by a cell from a transmission light image.
Examples
The first line in each notebook should enable the correct backend.
>>> %matplotlib widget
In a notebook cell, create the UI:
>>> names = sorted(glob("*.tif")) >>> imgs = {n: io.ImageSequence(n).open()[0] ... for n in names} # 1st frame from each sequence >>> rs = ROISelector(imgs) >>> rs
Now one can draw ROIs on each image. It is also possible to define multiple categories such as “cell” and “background”:
>>> rs.categories = ["cell", "background"]
By setting the
auto_category
attribute to True, after drawing a ROI, the next category will be enabled automatically, allowing for quick selection of different ROIs within the same image.>>> rs.auto_category = True
Via
multi
, selection of multiple ROIs per image and category can be enabled and disabled.>>> rs.multi = True
Once finished, the ROIs can be accessed via the
rois
attribute, which is a list of dicts mapping category -> ROI (or simply a list of ROIs if no categories were defined).>>> rs.rois [{'cat1': RectangleROI(top_left=(52.5, 27.8), bottom_right=(117.2, 68.8)), 'cat2': RectangleROI(top_left=(25.3, 35.7), bottom_right=(60.8, 67.2))}, {'cat1': PathROI(<48 vertices>), 'cat2': PathROI(<30 vertices>)}]
- Parameters:
images (Sequence | Dict) – List of image (sequences) to populate
images
.**kwargs – Passed to parent
__init__
.
- images#
Images or sequences to select from. See
ImageSelector
documentation for details.
- rois: List#
Each list entry corresponds to one entry in
images
. An entry can be either a single ROI, a list of ROIs (ifmulti
is True, or a dict mapping a category name to a ROI or list of ROIs.
- categories: List[str]#
ROI categories. If empty, there is just one (unnamed) category.
- multi: bool#
Whether to enable selection of mulitple ROIs per image und category
- class sdt.nbui.FileDialog(**kwargs)[source]#
File selection dialog
- Parameters:
cur_dir (Path) – Current directory
*args – Passed to super class constructor
**kwargs – Passed to super class constructor
- selected#
List of selected files
- cur_dir#
Current directory
- class sdt.nbui.ImageDisplay(**kwargs)[source]#
Widget to display an image
Additionally, a slider to set black and white points is provided.
- Parameters:
ax (matplotlib.axes._axes.Axes) – Axes instance to use for plotting
input (numpy.ndarray | None) – Image array to display
cmap (str | matplotlib.colors.Colormap) – Colormap for image display
**kwargs – Passed to parent
__init__
.
- ax: Axes#
Axes instance to use for plotting
- cmap: str | Colormap#
Colormap for image display
- input: ndarray | None#
Image array to display
- class sdt.nbui.ImageSelector(**kwargs)[source]#
UI element to select an image sequence and frame number
Given a list of file names, images, or image sequences, this allows the user to chose one of entry and also to select a frame number. The selected image is available via the
output
traitlet.- Parameters:
images (Sequence | Dict) – List of image (sequences) to populate
images
.**kwargs – Passed to parent
__init__
.
- output#
2D array representing the currently selected frame.
- images#
Images or sequences to select from. Image sequences can be passed as 3D
numpy.ndarray
, as lists of 2D arrays, or as paths to image files, which will be opened usingio.ImageSequence
. Single images are represented as 2D arrays.This attribute can be a list of
(key, img)
tuples wherekey
is the name to display and value an image (sequence), a dict mappingkey
toimg
(which will be converted to a list of tuples) or a plain list of image (sequence).
- property show_file_buttons: bool#
Whether to show “back” and “forward” buttons for file selection
- class sdt.nbui.ChannelSplitter(**kwargs)[source]#
Find regions of different imaging channels recorded with same camera
If several channels are recorded side-by-side on the same camera chip, find the region for each channel by drawing corresponding rectangles on representative images.
- Parameters:
n_channels – Number of channels present on the images
*args – Passed to superclass constructor
**kwargs – Passed to superclass constructor
- input: ndarray#
Image to display
- same_size#
If True, all channels are forced to be the same size
- colors: List[str] = ['C1', 'C8', 'C6', 'C2', 'C9']#
Colors to use for drawing the channel ROIs
- channel_names: Tuple[str, ...]#
Channel names as displayed in the tab titles