数据格式转换
# -*- coding: utf-8 -*-
import os
from wand.image import Image
# from PIL import Image # 一开始在这里报错是因为import 一个文件的时候,不能重名,在windows下需要安装一个exe
def get_imlist(path):
"""返回目录中所有tif图像的文件名列表"""
# return [os.path.join(path,f) for f in os.listdir(path) if f.endswith(".tif")]
return [os.path.join(path,f) for f in os.listdir(path) if f.endswith(".jpg")]
if __name__ == '__main__':
path = "E:/lab/1"
listdir = get_imlist(path)
for dir in listdir:
print(dir)
with Image(filename = str(dir)) as img:
img.resize(256,256) # width, height
# 存的目录为"G:/Test/6-28/HBsAg_png/",用了一步replace,换了个目录
img.save(filename = (str(dir)[:-3]+'png').replace("E:/lab/1", "E:/lab/dataset-png-24(128,source)/"))
# png, jpg, bmp, gif, tiff All OK--
https://github.com/amonod/hdrplus-python
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import os
from tqdm import tqdm
# "tqdm" is uitilized to show the progress bar.
#def get_imlist(path):
# return [os.path.join(path,f) for f in os.listdir(path) if f.endswith(".npy")]
if __name__ == '__main__':
folder = "/data/DISCNet-main/datasets/raw/raw/"
def load_images_from_folder(folder):
img = []
for filename in tqdm(os.listdir(folder)):
img = np.load(os.path.join(folder,filename))
img = np.clip(np.power(img*1000000, 1/2.2), 0, 500)
img = img/img.max()*255
cv2.imwrite('/data/DISCNet-main/datasets/raw/raw1/' + filename[:-3] +'npy', img[:,:,::-1])
return img
load_images_from_folder(folder)