Commit 3884faf0 authored by surgan12's avatar surgan12 Committed by Francisco Massa
Browse files

Pad updated (#683)

* pad updated

* checked pad

* pad checked

* pad checked
parent 8bd05e67
...@@ -288,6 +288,12 @@ def pad(img, padding, fill=0, padding_mode='constant'): ...@@ -288,6 +288,12 @@ def pad(img, padding, fill=0, padding_mode='constant'):
'Padding mode should be either constant, edge, reflect or symmetric' 'Padding mode should be either constant, edge, reflect or symmetric'
if padding_mode == 'constant': if padding_mode == 'constant':
if img.mode == 'P':
palette = img.getpalette()
image = ImageOps.expand(img, border=padding, fill=fill)
image.putpalette(palette)
return image
return ImageOps.expand(img, border=padding, fill=fill) return ImageOps.expand(img, border=padding, fill=fill)
else: else:
if isinstance(padding, int): if isinstance(padding, int):
...@@ -301,6 +307,14 @@ def pad(img, padding, fill=0, padding_mode='constant'): ...@@ -301,6 +307,14 @@ def pad(img, padding, fill=0, padding_mode='constant'):
pad_right = padding[2] pad_right = padding[2]
pad_bottom = padding[3] pad_bottom = padding[3]
if img.mode == 'P':
palette = img.getpalette()
img = np.asarray(img)
img = np.pad(img, ((pad_top, pad_bottom), (pad_left, pad_right)), padding_mode)
img = Image.fromarray(img)
img.putpalette(palette)
return img
img = np.asarray(img) img = np.asarray(img)
# RGB image # RGB image
if len(img.shape) == 3: if len(img.shape) == 3:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment