edit _unpadfunc
@@ -19,31 +19,32 @@ def unpad(im, pad_width):
A use case for this is when using ``skimage.morphology.skeletonize_3d``
to ensure that the skeleton extends beyond the edges of the image.
"""
- padded = np.pad(im, pad_width=pad_width,
- mode='constant', constant_values=1)
-
if type(pad_width) == int:
new_pad_width = []
for r in range (0,len(im.shape)):
new_pad_width.append(pad_width)
pad_width = new_pad_width
- if type(pad_width) == list:
+ if type(pad_width) == list and np.ndim (pad_width) == 1:
pad_width = np.asarray(pad_width)
shape = im.shape - pad_width[0] - pad_width[1]
-
- difference = (pad_width[0]-pad_width[1])
if shape[0] < 1:
shape = np.array(im.shape) * shape
- center = np.array(im.shape)
- center[0] = shape[0]/2 -difference
- center[1] = shape[1]/2 -difference
s_im = []
for dim in range(im.ndim):
- r = shape[dim] / 2
lower_im = pad_width[0]
upper_im = shape[dim] + pad_width[0]
s_im.append(slice(int(lower_im), int(upper_im)))
+ if type(pad_width) == list and np.ndim (pad_width) == 2:
+ pad_width = np.asarray(pad_width)
+ shape = np.asarray(im.shape)
+ s_im = []
+ for dim in range(im.ndim):
+ shape[dim] = im.shape[dim] - pad_width[dim][0] - pad_width[dim][1]
+ lower_im = pad_width[dim][0]
+ upper_im = shape[dim] + pad_width[dim][0]
+ s_im.append(slice(int(lower_im), int(upper_im)))
+
return im[tuple(s_im)]
\ No newline at end of file
