To resize and save a 16-bits numpy array as an image using PIL, follow these steps:

  1. Import the required libraries:
import numpy as np
from PIL import Image
  1. Create a numpy array with 16-bit values:
arr = np.random.randint(0, 2**16-1, size=(512, 512), dtype=np.uint16)
  1. Convert the numpy array to a PIL image:
img = Image.fromarray(arr)
  1. Resize the image to the desired size:
img_resized = img.resize((256, 256))
  1. 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.

how to resize and save an 16-bits numpy array to Image using PIL

原文地址: http://www.cveoy.top/t/topic/btw9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录