Ejemplo n.º 1
0
 def as_contours(self):
     """A dictionary of lists of contours keyed by byte_value"""
     contours = dict()
     for byte_value in self.__byte_values:
         if byte_value == 0:
             continue
         mask = (self.__array == byte_value) * 255
         found_contours = find_contours(
             mask, 254, fully_connected='high')  # a list of array
         contours[byte_value] = ContourSet(found_contours)
     return contours
Ejemplo n.º 2
0
Archivo: extra.py Proyecto: asa008/ahds
 def _as_contours(self):
     """A dictionary of lists of contours keyed by byte_value"""
     contours = dict()
     _maskbase = np.array([False, True])
     _indexbase = np.zeros(self._array.shape, dtype=np.int8)
     for byte_value in self._byte_values[self._byte_values != 0]:
         mask = _maskbase[np.equal(self._array, byte_value, out=_indexbase)]
         found_contours = find_contours(
             mask, 254, fully_connected='high')  # a list of array
         contours[byte_value] = ContourSet(found_contours)
     return contours
Ejemplo n.º 3
0
def feret_diameter(prop):
    """Determines the maximum Feret diameter.

    Parameters
    ----------
    prop : RegionProperties
        Describes a labeled region.

    Returns
    -------
    max_feret_diameter : float
        Maximum Feret diameter of the region.

    See also
    --------
    :func:`skimage.measure.regionprops` : Measure properties of labeled image regions

    Examples
    --------
    >>> import numpy as np
    >>> from skimage.measure import regionprops
    >>> image = np.ones((2,2), dtype=np.int8)
    >>> prop = regionprops(image)[0]
    >>> feret_diameter(prop)
    2.23606797749979

    """
    identity_convex_hull = np.pad(prop.convex_image,
                                  2,
                                  mode='constant',
                                  constant_values=0)
    if prop._ndim == 2:
        coordinates = np.vstack(
            find_contours(identity_convex_hull, 0.5, fully_connected='high'))
    elif prop._ndim == 3:
        coordinates, _, _, _ = marching_cubes(identity_convex_hull, level=0.5)
    distances = pdist(coordinates, 'sqeuclidean')
    # TODO: allow computing the Feret diameter along a given direction (t,s)
    # For this, restrict the maximum distance to those pairwise distances whose
    # orientation (up to a given tolerance) is (t,s)
    max_feret_diameter = sqrt(np.max(distances))
    return max_feret_diameter