straditize.label_selection module¶
Module for the LabelSelection
class
This module defines the LabelSelection
class, a base class for the
straditize.straditizer.Straditizer
straditize.binary.DataReader
classes. This class implements the
features to select parts of an image and deletes them. The
straditize.widgets.selection_toolbar.SelectionToolbar
interfaces
with instances of this class.
Disclaimer
Copyright (C) 2018-2019 Philipp S. Sommer
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Classes
Class to provide selection functionalities for an image |
-
class
straditize.label_selection.
LabelSelection
[source]¶ Bases:
object
Class to provide selection functionalities for an image
This class provides functionalities to select features in an image. A new selection can be started through
enable_label_selection()
method and selected parts can be removed through theremove_selected_labels()
method.A 2D boolean mask of the selected pixels can be accessed through the
selected_part
attribute.This class generally assumes that the array for the selection is a 2D integer array, e.g. obtained from the
skimage.morphology.label()
function.The selection of labels is handled through the colormap. The selection is displayed as a matplotlib image on the
ax
attribute of this instance. If the color for one label is equal to thecselect
color, it is considered as selected. Additionally every cell that has a value greater than the original number of labels is considered to be selected.Cells with a value of -1 are not selected and cells with a value of 0 cannot be selected.
Attributes
The RGBA color for selected polygons
The RGBA color for unselected polygons
List of attribute names of arrays that should be modified if the labels are about to be removed.
Functions that shall be called before the labels are removed.
The selected part as a 2D boolean mask
A list of selected labels in the selection array
The selected part as a 2D boolean mask
Methods
copy_cmap
(cmap_src, colors)Copy a colormap with replaced colors
disable_label_selection
([remove])Disable the label selection
enable_label_selection
(arr, ncolors[, img, …])Start the selection of labels
get_default_cmap
(ncolors)The default colormap for binary images
Highlight labels that cover only a small portion of cells
pick_label
(event)Pick the label selected by the given mouseevent
remove_selected_labels
([disable])Remove the selected parts of the diagram
Remove the ellipes for small features
Select the entire array
Invert the selection
select_labels
(selected)Select a list of labels
Clear the selection
-
cid_select
= None¶
-
static
copy_cmap
(cmap_src, colors)[source]¶ Copy a colormap with replaced colors
This function creates a method that has the same name and the same under, over and bad values as the given cmap_src but with replaced colors
- Parameters
cmap_src (matplotlib.colors.Colormap) – The source colormap
colors (np.ndarray) – The colors for the colormap
- Returns
The new colormap
- Return type
-
cselect
= [1.0, 0.0, 0.0, 1.0]¶ The RGBA color for selected polygons
-
cunselect
= [0.0, 0.0, 0.0, 0.0]¶ The RGBA color for unselected polygons
-
disable_label_selection
(remove=None)[source]¶ Disable the label selection
This will disconnect the pick_event and remove the selection images
- Parameters
remove (bool) – Whether to remove the selection image from the plot. If None, the
_remove
attribute is used
-
enable_label_selection
(arr, ncolors, img=None, set_picker=False, **kwargs)[source]¶ Start the selection of labels
- Parameters
arr (2D np.ndarray of dtype int) – The labeled array that contains the features to select.
ncolors (int) – The maximum of the labels in arr
img (matplotlib image) – The image for the selection. If not provided, a new image is created
set_picker (bool) – If True, connect the matplotlib pick_event to the
pick_label()
method
-
highlight_small_selections
(n=20)[source]¶ Highlight labels that cover only a small portion of cells
This method uses the
skimage.morphology.remove_small_objects()
to detect and highlight small features in the diagram. Each feature will be highlighted through an ellipsis around it.See also
-
label_arrs
= []¶ List of attribute names of arrays that should be modified if the labels are about to be removed. The attributes might be callable and should then provide the array
-
remove_callbacks
= None¶ Functions that shall be called before the labels are removed. The keys must be the attributes in the
label_attrs
list, values must be list of function that accept too arguments, the array and the boolean mask highlighting the cells that will be set to 0
-
remove_selected_labels
(disable=False)[source]¶ Remove the selected parts of the diagram
This method will call the callbackes in the
remove_callbacks
attribute for all the attributes in thelabel_arrs
list.- Parameters
disable (bool) – If True, call the
disable_label_selection()
method at the end
-
remove_small_selection_ellipses
()[source]¶ Remove the ellipes for small features
Removes the ellipses plotted by the
highlight_small_selections()
method
-
select_labels
(selected)[source]¶ Select a list of labels
- Parameters
selected (np.ndarray) – The numpy array of labels that should be selected
-
property
selected_labeled_part
¶ The selected part as a 2D boolean mask
-
property
selected_labels
¶ A list of selected labels in the selection array
-
property
selected_part
¶ The selected part as a 2D boolean mask
-