.mat文件转换为png
将CFD(CrackForest Datasets)数据集的GroundTruth中的.mat文件转换为便于使用的maskpng
dotmat2png.py
import scipy.io import numpy as np import cv2 import os def save_mask(mat_file, save_path): mat = scipy.io.loadmat(mat_file) 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(save_path, np_seg) print('save mask:', save_path) def main(): mat_dir = './groundTruth/' # mat文件的路径 save_dir = './mask/' # 保存为maskpng的路径 自己创建 mat_files = os.listdir(mat_dir) for mat_file in mat_files: save_mask(mat_dir + mat_file, save_dir + mat_file.split('.')[0] + '.png') main()
原始.mat文件,如下:
转换后的maskpng图片,如下:
对应原始图片,如下:
修改后的CFD数据集链接:CFD数据集