spateo.tools.live_wire ====================== .. py:module:: spateo.tools.live_wire .. autoapi-nested-parse:: This file implements the LiveWire segmentation algorithm. The code is ported from: 1. https://github.com/pdyban/livewire: LiveWireSegmentation and compute_shortest_path functions/class. 2. https://github.com/Usama3627/live-wire: include the _compute_graph and compute_shortest_path functions. Classes ------- .. autoapisummary:: spateo.tools.live_wire.LiveWireSegmentation Functions --------- .. autoapisummary:: spateo.tools.live_wire.compute_shortest_path spateo.tools.live_wire.live_wire Module Contents --------------- .. py:class:: LiveWireSegmentation(image: Optional = None, smooth_image: bool = False, threshold_gradient_image: bool = False) Bases: :py:obj:`object` .. py:attribute:: _image :value: None .. py:attribute:: edges :value: None .. py:attribute:: G :value: None .. py:attribute:: smooth_image :value: False .. py:attribute:: threshold_gradient_image :value: False .. py:property:: image .. py:method:: _smooth_image() .. py:method:: _compute_gradient_image() .. py:method:: _threshold_gradient_image() .. py:method:: _compute_graph() .. py:method:: compute_shortest_path(startPt, endPt) .. py:function:: compute_shortest_path(image: numpy.ndarray, startPt: Tuple[float, float], endPt: Tuple[float, float]) -> List 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. :param image: image on which the shortest path should be computed :param startPt: starting point for path computation :param endPt: target point for path computation :returns: shortest path as a list of tuples (x, y), including startPt and endPt :rtype: path .. py:function:: live_wire(image: numpy.ndarray, smooth_image: bool = False, threshold_gradient_image: bool = False, interactive: bool = True) -> List[numpy.ndarray] 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. :param image: image on which the shortest path should be computed. :param smooth_image: Whether to smooth the original image using bilateral smoothing filter. :param threshold_gradient_image: Wheter to use otsu method generate a thresholded gradient image for shortest path computation. :param 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.