CrackForest数据集| .mat转为.png

数据集下载

CrackForest数据集
https://github.com/cuilimeng/CrackForest-dataset

转化代码

input_folder = 'xxxxxxxxx'

# 输出文件夹路径
output_folder = 'xxxxxxxxx'

# 遍历文件夹中的.mat文件
for filename in os.listdir(input_folder):
    if filename.endswith('.mat'):
        print(filename)
        # 构建完整的文件路径
        mat_filepath = os.path.join(input_folder, filename)

        # 从.mat文件中加载数据
        mat = scipy.io.loadmat(mat_filepath)

        np_seg = mat['groundTruth'][0][0][0]
        (y, x) = np.where(np_seg == 2)
        np_seg[y, x] = 255
        (y, x) = np.where(np_seg == 1)
        np_seg[y, x] = 0

        cv2.imwrite(output_folder+filename+'.png', np_seg)

猜你喜欢

转载自blog.csdn.net/holly_Z_P_F/article/details/135224219