spateo.tools.live_wire¶
- This file implements the LiveWire segmentation algorithm. The code is ported from:
https://github.com/pdyban/livewire: LiveWireSegmentation and compute_shortest_path functions/class.
https://github.com/Usama3627/live-wire: include the _compute_graph and compute_shortest_path functions.
Classes¶
Functions¶
|
Inline function for easier computation of shortest_path in an image. |
|
Use LiveWire segmentation algorithm for image segmentation aka intelligent scissors. The general idea of the |
Module Contents¶
- class spateo.tools.live_wire.LiveWireSegmentation(image: Optional = None, smooth_image: bool = False, threshold_gradient_image: bool = False)[source]¶
Bases:
object
- spateo.tools.live_wire.compute_shortest_path(image: numpy.ndarray, startPt: Tuple[float, float], endPt: Tuple[float, float]) List [source]¶
Inline function for easier computation of shortest_path in an image. This function will create a new instance of LiveWireSegmentation class every time it is called, calling for a recomputation of the gradient image and the shortest path graph. If you need to compute the shortest path in one image more than once, use the class-form initialization instead.
- Parameters:
- image
image on which the shortest path should be computed
- startPt
starting point for path computation
- endPt
target point for path computation
- Returns:
shortest path as a list of tuples (x, y), including startPt and endPt
- Return type:
path
- spateo.tools.live_wire.live_wire(image: numpy.ndarray, smooth_image: bool = False, threshold_gradient_image: bool = False, interactive: bool = True) List[numpy.ndarray] [source]¶
Use LiveWire segmentation algorithm for image segmentation aka intelligent scissors. The general idea of the algorithm is to use image information for segmentation and avoid crossing object boundaries. A gradient image highlights the boundaries, and Dijkstra’s shortest path algorithm computes a path using gradient differences as segment costs. Thus the line avoids strong gradients in the gradient image, which corresponds to following object boundaries in the original image.
Now let’s display the image using matplotlib front end. A click on the image starts livewire segmentation. The suggestion for the best segmentation will appear as you will be moving mouse across the image. To submit a suggestion, click on the image for the second time. To finish the segmentation, press Escape key.
- Parameters:
- image
image on which the shortest path should be computed.
- smooth_image
Whether to smooth the original image using bilateral smoothing filter.
- threshold_gradient_image
Wheter to use otsu method generate a thresholded gradient image for shortest path computation.
- interactive
Wether to generate the path interactively.
- Returns:
A list of paths that are generated when running this algorithm. Paths can be used to segment a particular spatial domain of interests.