Saving 16-bit NumPy Arrays as Images with OpenCV
To save a 16-bit NumPy array as an image, you can use the 'imwrite' function from the OpenCV library. Here's an example:
import cv2
import numpy as np
# create a 16-bit numpy array
arr = np.random.randint(0, 65536, size=(512, 512), dtype=np.uint16)
# save the array as an image
cv2.imwrite('image.png', arr)
In this example, we create a random 512x512 NumPy array with values between 0 and 65535 (the maximum value for a 16-bit integer). Then, we use 'cv2.imwrite' to save the array as a PNG image file. The function automatically handles the conversion of the NumPy array to an image format.
AI 优化版
原文地址:https://www.cveoy.top/t/topic/mWZB 著作权归作者所有。请勿转载和采集!