how to resize and save an 16-bits numpy array to Image using PIL
To resize and save a 16-bits numpy array as an image using PIL, follow these steps:
- Import the required libraries:
import numpy as np
from PIL import Image
- Create a numpy array with 16-bit values:
arr = np.random.randint(0, 2**16-1, size=(512, 512), dtype=np.uint16)
- Convert the numpy array to a PIL image:
img = Image.fromarray(arr)
- Resize the image to the desired size:
img_resized = img.resize((256, 256))
- Save the resized image:
img_resized.save('resized_image.png')
Note: when saving the image, make sure to choose a file format that supports 16-bit images, such as PNG or TIFF.
原文地址: http://www.cveoy.top/t/topic/btw9 著作权归作者所有。请勿转载和采集!