def skeletonize_3d(img):
 if ((img.ndim < 2) or (img.ndim > 3)):
  raise ValueError(('skeletonize_3d can only handle 2D or 3D images; got img.ndim = %s instead.' % img.ndim))
 img = np.ascontiguousarray(img)
 img = img_as_ubyte(img, force_copy=False)
 img_o = img
 if (img.ndim == 2):
  img_o = img[np.newaxis, ...]
 img_o = np.pad(img_o, pad_width=1, mode='constant')
 maxval = img_o.max()
 img_o[(img_o != 0)] = 1
 img_o = np.asarray(_compute_thin_image(img_o))
 img_o = crop(img_o, crop_width=1)
 if (img.ndim == 2):
  img_o = img_o[0]
 img_o *= maxval
 return img_o

def skeletonize_3d ( img ) : if ( ( img . ndim < 2 ) or ( img . ndim > 3 ) ) : raise ValueError ( ( 'skeletonize_3d can only handle 2D or 3D images; got img.ndim = %s instead.' % img . ndim ) ) img = np . ascontiguousarray ( img ) img = img_as_ubyte ( img , force_copy = False ) img_o = img if ( img . ndim == 2 ) : img_o = img [ np . newaxis , ... ] img_o = np . pad ( img_o , pad_width = 1 , mode = 'constant' ) maxval = img_o . max ( ) img_o [ ( img_o != 0 ) ] = 1 img_o = np . asarray ( _compute_thin_image ( img_o ) ) img_o = crop ( img_o , crop_width = 1 ) if ( img . ndim == 2 ) : img_o = img_o [ 0 ] img_o *= maxval return img_o
compute the skeleton of a binary image .