def pad_for_eccentric_selems(func):
 @functools.wraps(func)
 def func_out(image, selem, out=None, *args, **kwargs):
  pad_widths = []
  padding = False
  if (out is None):
   out = np.empty_like(image)
  for axis_len in selem.shape:
   if ((axis_len % 2) == 0):
    axis_pad_width = (axis_len - 1)
    padding = True
   else:
    axis_pad_width = 0
   pad_widths.append(((axis_pad_width,) * 2))
  if padding:
   image = np.pad(image, pad_widths, mode='edge')
   out_temp = np.empty_like(image)
  else:
   out_temp = out
  out_temp = func(image, selem, out=out_temp, *args, **kwargs)
  if padding:
   out[:] = crop(out_temp, pad_widths)
  else:
   out = out_temp
  return out
 return func_out

def pad_for_eccentric_selems ( func ) : @ functools . wraps ( func ) def func_out ( image , selem , out = None , * args , ** kwargs ) : pad_widths = [ ] padding = False if ( out is None ) : out = np . empty_like ( image ) for axis_len in selem . shape : if ( ( axis_len % 2 ) == 0 ) : axis_pad_width = ( axis_len - 1 ) padding = True else : axis_pad_width = 0 pad_widths . append ( ( ( axis_pad_width , ) * 2 ) ) if padding : image = np . pad ( image , pad_widths , mode = 'edge' ) out_temp = np . empty_like ( image ) else : out_temp = out out_temp = func ( image , selem , out = out_temp , * args , ** kwargs ) if padding : out [ : ] = crop ( out_temp , pad_widths ) else : out = out_temp return out return func_out
pad input images for certain morphological operations .