UMN数据集拆分获取

数据集为黄斑水肿分割数据,包含700+张,29个黄斑水肿受试者的眼底图像,及两组专家手动标定图像。
数据集地址:http://people.ece.umn.edu/users/parhi/.DATA/OCT/DME/
UMNDataset.mat
在这里插入图片描述
在这里插入图片描述
处理UMNDataset.mat,转换成图片

#仅处理UMNDataset.mat
import cv2
import scipy.io as scio
import os

folder = r'I:/02OCT/OCTdataset/UMN'  #此文件夹下只有UMNDataset.mat一个文件 I:/02OCT/OCTdataset/UMN/UMNDataset.mat
path = os.listdir(folder)
srcdst = 'I:/02OCT/OCTdataset/UMNDataset/srcimg/'
m1dst = 'I:/02OCT/OCTdataset/UMNDataset/manual1/'
m2dst = 'I:/02OCT/OCTdataset/UMNDataset/manual2/'

for each_mat in path:
    print(each_mat)
    first_name, second_name = os.path.splitext(each_mat)
    print('mat名',first_name)
    # 拆分.mat文件的前后缀名字,注意是**路径**
    each_mat = os.path.join(folder, each_mat)
    array_struct = scio.loadmat(each_mat)

    img_data = array_struct['AllSubjects']# 原图像
    row_len_out = len(img_data[0])
    row_len_inner = img_data[0][0].shape[2]
    print(row_len_inner)
    for i in range(row_len_out):
        for j in range(row_len_inner):
            cv2.imwrite(srcdst + 'img' + str(i) +'index'+str(j)+ '.jpg', img_data[0][i][:, :, j])

    manual1_data = array_struct['ManualFluid1']  # 标注1
    row_len_out = len(manual1_data[0])
    row_len_inner = manual1_data[0][0].shape[2]
    print(row_len_inner)
    for i in range(row_len_out):
        for j in range(row_len_inner):
            cv2.imwrite(m1dst + 'img' + str(i) + 'index' + str(j) + '.jpg', manual1_data[0][i][:, :, j])

    manual2_data = array_struct['ManualFluid2']  # 标注2
    row_len_out = len(manual2_data[0])
    row_len_inner = manual2_data[0][0].shape[2]
    print(row_len_inner)
    for i in range(row_len_out):
        for j in range(row_len_inner):
            cv2.imwrite(m2dst + 'img' + str(i) + 'index' + str(j) + '.jpg', manual2_data[0][i][:, :, j])

上面获取到的原图像可以正常显示,但是手动标记图像不能正常显示。再进行一次转换

#转换[0,1] -> [0,255] 手动标记获取
import cv2, os
m1dst = 'I:/02OCT/OCTdataset/UMNDataset/manual1/'
m2dst = 'I:/02OCT/OCTdataset/UMNDataset/manual2/'
#print(os.listdir(r'/Users/hjy/Desktop/blues'))

def changeImg(gray):
    H, W = gray.shape
    for i in range(0, W):
        for j in range(0, H):
            if gray[j, i] != 0:
                gray[j, i] = 255
    return gray

list = os.listdir(m1dst)
for i in list:
    print(i)
    img1 = cv2.imread(m1dst+i,0)
    img2 = cv2.imread(m2dst+i,0)
    img1 = changeImg(img1)
    img2 = changeImg(img2)
    cv2.imwrite(m1dst+i,img1)
    cv2.imwrite(m2dst+i,img2)
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值