8位深度转换为24位深度,24位深度转换为8位深度

8位深度转换为24位深度

import os
import numpy as np
import PIL
from PIL import Image
import cv2

path = "png_512/test/img" #需要转化的文件夹路径,jpg和png都能一起批量转化(8转24)
for file in os.listdir(path):
#     print("files:",os.path.join(root,file))
    filename = os.path.join(path,file)
    img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
    img_shape = img.shape
    imgs = np.zeros(shape=(img_shape[0], img_shape[1], 3), dtype=np.float32)
    imgs[:, :, 0] = img[:, :]
    imgs[:, :, 1] = img[:, :]
    imgs[:, :, 2] = img[:, :]
    cv2.imwrite(f'png_512_24/test/img/{file}', imgs)

24位深度转换为8位深度

import os
import numpy as np
import PIL
from PIL import Image
import cv2

path = "png_256_(0-255)_24_8/val/labelcol" #需要转化的文件夹路径,jpg和png都能一起批量转化(8转24)
for file in os.listdir(path):
#     print("files:",os.path.join(root,file))
    filename = os.path.join(path,file)
    img = cv2.imread(filename) # 填要转换的图片存储地址
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(f'png_256_(0-255)_24_8/val/label/{file}', img)

# img = cv2.imread(r'C:\Users\room.png') # 填要转换的图片存储地址
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imwrite(r'C:\Users\room8.png',img) # 填转换后的图片存储地址,若在同一目录,则注意不要重名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值