图像像素0-1转换为0-255 import matplotlib.pyplot as plt from skimage import io,data import os import cv2 import pydicom import numpy as np import nibabel as nib import SimpleITK as sitk import matplotlib.pyplot as plt %matplotlib inline folderPath = 'new_png_256' for folder in os.listdir(folderPath): # new_png_256\test file_path = os.path.join(folderPath,folder) for file in os.listdir(file_path): # new_png_256\test\img img_path = os.path.join(file_path,file) for img in os.listdir(img_path): image_path = os.path.join(img_path,img) image = cv2.imread(image_path) image = (np.maximum(image, 0) / image.max()) * 255.0 image = np.uint8(image) cv2.imwrite(f'png_256_0-255/{folder}/{file}/{img}',image) #save_path为保存路径