16位灰度图转RGB图
点击查看代码
import cv2
import numpy as np
from PIL import Image
def transfer_16bit_to_8bit(image_path):
image_16bit=Image.open(image_path)
img_array = np.array(image_16bit, dtype=np.uint16)
min_16bit = np.min(img_array)
max_16bit = np.max(img_array)
image_8bit = np.array(np.rint(255 * ((image_16bit - min_16bit) / (max_16bit - min_16bit))), dtype=np.uint8)
colored_image=cv2.cvtColor(image_8bit,cv2.COLOR_GRAY2BGR)
cv2.imshow('8bit',colored_image)
cv2.waitKey(0)
return colored_image
image_path = r'D:\pic\2024demo03\pic\tif_backup\1.00kV_T1_6500×_17.tif'
colored_image=transfer_16bit_to_8bit(image_path)
cv2.imwrite(r"D:\pic\2024demo03\pic\tif\1.00kV_T1_6500×_17.tif",colored_image)