栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

16位图转8位图 (python)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

16位图转8位图 (python)

16位图转8位图 (python)
import cv2
import numpy as np
import os
from PIL import Image

path=r"E:\AI_datas\3-16Bit\3"
save_path=r"E:\AI_datas\3-16Bit\4"
for name in os.listdir(path):
    if name.split('.')[-1]=='tif':
        new_path=os.path.join(path,name)
        uint16_img = cv2.imread(new_path,-1)
        #uint16_img1 = Image.open(new_path)
        #Image_p=Image.fromarray(uint16_img)
        uint16_img -= uint16_img.min()
        uint16_img = uint16_img / (uint16_img.max() - uint16_img.min())
        uint16_img *= 255
        new_uint16_img = uint16_img.astype(np.uint8)

        # M=cv2.getRotationMatrix2D((uint16_img.shape[0]/2,uint16_img.shape[1]/2),45,0.8)
        # uint16_img=cv2.warpAffine(uint16_img,M,(cols, rows))

        basename=name.split('.')[0]
        # uint16_img=Image.fromarray(uint16_img)
        # uint16_img.save(os.path.join(save_path,basename)+'.png')

        cv2.imwrite(os.path.join(save_path,basename)+'.bmp', uint16_img)
        print(os.path.join(save_path,name))
        # cv2.waitKey(0)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/674952.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号