数据集为黄斑水肿分割数据,包含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)