ocrd_cis/ocropy/ocrolib/morph.py
def label(image,**kw):
    """Implement the scipy.ndimage.measurements.label function
    via much faster OpenCV.connectedComponents.
    
    Return a tuple:
    - same-size Numpy array with integer labels for fg components
    - number of components (eq. largest label)
    """
    n, labels = cv2.connectedComponents(image.astype(uint8))
    #n, labels = cv2.connectedComponentsWithAlgorithm(image.astype(uint8), connectivity=4, ltype=2, ccltype=cv2.CCL_DEFAULT)
    return labels, n
    # try: return measurements.label(image,**kw)
    # except: pass
    # types = ["int32","uint32","int64","uint64","int16","uint16"]
    # for t in types:
    #     try: return measurements.label(array(image,dtype=t),**kw)
    #     except: pass
    # # let it raise the same exception as before
    # return measurements.label(image,**kw)
Implement the scipy.ndimage.measurements.label function
    via much faster OpenCV.connectedComponents.
    
    Return a tuple:
    - same-size Numpy array with integer labels for fg components
    - number of components (eq. largest label)
    


Return a tuple:
same-size Numpy array with integer labels for fg components
number of components (eq. largest label)
Return a tuple : same - size Numpy array with integer labels for fg components number of components ( eq . largest label )
def label(image,**kw):
    n, labels = cv2.connectedComponents(image.astype(uint8))
    return labels, n
def label ( image , ** kw ) : n , labels = cv2 . connectedComponents ( image . astype ( uint8 ) ) return labels , n
Implement the scipy.ndimage.measurements.label function
via much faster OpenCV.connectedComponents.
Implement the scipy . ndimage . measurements . label function via much faster OpenCV . connectedComponents .
"""Implement the scipy.ndimage.measurements.label function
    via much faster OpenCV.connectedComponents.
    
    Return a tuple:
    - same-size Numpy array with integer labels for fg components
    - number of components (eq. largest label)
    """ #n, labels = cv2.connectedComponentsWithAlgorithm(image.astype(uint8), connectivity=4, ltype=2, ccltype=cv2.CCL_DEFAULT) # try: return measurements.label(image,**kw) # except: pass # types = ["int32","uint32","int64","uint64","int16","uint16"] # for t in types: #     try: return measurements.label(array(image,dtype=t),**kw) #     except: pass # # let it raise the same exception as before # return measurements.label(image,**kw)
image