x光肺部分割数据集_BSDS500分割数据集的下载及简单处理

这篇博客介绍了如何将BSDS500数据集中的groundtruth mat文件转换为jpg格式。通过Python代码,读取MAT文件并将其转换为图像,保存在新的文件夹中。此外,揭示了数据集中存在多个ground truth的事实。
摘要由CSDN通过智能技术生成

由于groundtruth是以mat格式存储的,所以有时用的时候需要先转换成jpg格式。从网上看了一下没找到能直接用的,于是参考bolg写了一个处理的代码。

将代码中的root换成你数据集实际所在位置,然后直接运行代码,就可以在你数据集文件夹 BSR\BSDS500\data 中多出一个GT_convert文件夹,就是转换后的结果。

from scipy importioimportscipyimportos###运行时需要改变root值为BSD500所在的相应根目录

root = 'F:\\lyc\\Data_Set\\BSR\\BSDS500'PATH= os.path.join(root,'data\\groundTruth')for sub_dir_name in ['train','test','val']:

sub_pth=os.path.join(PATH,sub_dir_name)##为生成的图片新建个文件夹保存

save_pth = os.path.join(root,'data\\GT_convert',sub_dir_name)

os.makedirs(save_pth,exist_ok=True)print('开始转换'+sub_dir_name+'文件夹中内容')for filename inos.listdir(sub_pth):#读取mat文件中所有数据

#mat文件里面是以字典形式存储的数据

#包括 dict_keys(['__globals__', 'groundTruth', '__header__', '__version__'])

#我们要用到'groundTruth']中的轮廓

#x['groundTruth'][0][0][0][0][1]为轮廓

#x['groundTruth'][0][0][0][0][0]为分割图

data =io.loadmat(os.path.join(sub_pth,filename))

edge_data= data['groundTruth'][0][0][0][0][1]#存储的是归一化后的数据:0

#因此需要还原回0

edge_data_255 = edge_data * 255new_img_name= filename.split('.')[0]+'.jpg'

print(new_img_name)

scipy.misc.imsave(os.path.join(save_pth,new_img_name), edge_data_255)#保存图片

参考其他bolg对数据集进行的处理,但是crf对其中中间模糊像素不进行处理,一直以为是作者自己对数据集进行扩充的,后来发现不是,如果自己扩充他就不会与未扩充的方法进行比较,原来多个ground truth就藏在这个数据集中

a = data['groundTruth'][0][1][0][0][1]*255

b = data['groundTruth'][0][2][0][0][1]*255

c = data['groundTruth'][0][3][0][0][1]*255

d = data['groundTruth'][0][4][0][0][1]*255

e = data['groundTruth'][0][5][0][0][1]*255

f = data['groundTruth'][0][0][0][0][1]*255

分别是6个ground truth。BSDS500数据集提出时只说是对BSDS300进行扩充,因此要看数据集具体构成要看BSDS300的论文。

另外:以mat存储的矩阵是可以用python直接读取的,因此并不一定要先转换成图片存储:

import scipy.io as scio

mat_path = './test.mat'

mat = scio.loadmat(mat_path)

就可以获取mat矩阵了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值