I'm trying to add 5 pixels worth of padding all around the image I have currently. The images are 150x150 pixels and I want to resize them into 160x160 with symmetric padding for my CNN.
Here is the code I am using:
for need_pad_img in os.listdir(old_images_path+'split_images'):
if need_pad_img.endswith(".jpg") and not need_pad_img.startswith("."):
image = Image.open(old_images_path + 'split_images/' + need_pad_img)
data = asarray(image)
new_data = np.pad(data, pad_width=5, mode='symmetric')
gen_img = Image.fromarray(new_data).astype(np.uint8).convert('RGB').save(old_images_path + 'split_images/' + "pad_" + need_pad_img)
However, I am getting error:
File "/opt/homebrew/Caskroom/miniforge/base/envs/env_tf/lib/python3.9/site-packages/PIL/Image.py", line 2751, in fromarray
raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e
TypeError: Cannot handle this data type: (1, 1, 13), |u1
When I run new_data.shape I get (160,160,13) and when I run new_data.dtype I get dtype('uint8').