API¶
Labeling¶
-
class
lwsspy.ml.labeling.segmentlabeler.SegmentLabeler(img, segmentation, labeldict={'410': 2, '660': 3, 'moho': 1, 'none': 9999}, loglevel=20)[source]¶ -
__init__(img, segmentation, labeldict={'410': 2, '660': 3, 'moho': 1, 'none': 9999}, loglevel=20)[source]¶ This class takes in an image, some corresponding segmentation e.g. (SLIC) and a label dictionary that can be used to label the image in an ‘intuitive’ GUI.
- Parameters
- imgndarray [w x h x 3]
Image
- segmentationndarray [w x h]
mask that has a unique nunmber for each segment such that it can be labeled.
- labeldictdict, optional
Dictionary of labels, must contain the ‘none’ keyword, which denotes the unlabeled value, by default {‘moho’: 1, ‘410’: 2, ‘660’: 3, ‘none’: 9999}
- loglevellogging.LOGLEVEL, optional
loglevel, used to debug the event loop. Not necessary to be modified, by default logging.INFO
Notes
- Authors
Lucas Sawade (lsawade@princeton.edu)
- Last Modified
2021.07.02 00.00 (Lucas Sawade)
Examples
The usage of this labeling is fairly straight forward. Given an image,
img, and a segmentation,segs, of said image, we instantiate the class and call the start labeling method.>>> from lwsspy.ml import SegmentLabeler >>> sl = SegmentLabeler(img, segments) >>> labeled_mask = sl.start_labeling()
This will open two figures. One contains the image by itself and the second one contains the image and the outlines of the mask. We will use the firs image for reference and the second image to actually label the image segments. The GUI has a few controls that can be used.
Control
Action
Mouse-left
Add label to segment
Mouse-right
Remove label to segment
Mouse-left-drag
Add labels to segments dragged over
Mouse-right-drag
Remove labels to segments dragged over
n
Next label
p
Previous label True
d
Delete previously labeled segment
esc
Close figure and return the currently selected mask
The currently selected mask will also be returned if any of the figures is closed.
The selected mask can then be viewed via
>>> import matplotlib.pyplot as plt >>> imshow(labeled_mask, aspect='auto')
Note that depending on the values you chose in the label dictionary you will have to create a colormap and norm that resembles the mask values.
-
-
class
lwsspy.ml.labeling.volumelabeler.VolumeLabeler(x, y, z, V, labeldict={'410': 2, '660': 3, 'moho': 1, 'none': 9999}, labeled: Optional[dict] = None)[source]¶ -
__init__(x, y, z, V, labeldict={'410': 2, '660': 3, 'moho': 1, 'none': 9999}, labeled: Optional[dict] = None)[source]¶ This class uses the :class:
lwsspy.ml.labeling.segementlabeler.SegmentLabelerto label slices in a volume. After instantiation, use the label method to label a Volumen of single Channel data.- Parameters
- xarraylike
x vector
- yarralike
y vector
- zarraylike
z vector
- Varraylike
3D array with data corresponding to vectors X x Y x Z direction.
- labeldictdict, optional
dictionary with labels, by default {‘moho’: 1, ‘410’: 2, ‘660’: 3, ‘none’: 9999}
- labeledOptional[dict], optional
Optional dictionary with labeled volume. Labeled should contain 4 variables lx, ly, lz, lV, where l{x,y,z} are boolean arrays that where defined as locations for labeled layers. Useful if you need to take a labeling break. Right now there is no way of resuming to an image make sure you finisshe the ones you have started, by default None
Notes
Things that I have to fix:
The volume should be allowed to be 3-channel data
Also allow for custom normalizations and colormaps
- Authors
Lucas Sawade (lsawade@princeton.edu)
- Last Modified
2021.07.02 00.00 (Lucas Sawade)
-