コード例 #1
0
def hard_sum(img_path1,img_path2):
    whole_data=[]
    img_name_list1,label_name_list1=tool.generate_list(img_path1,img_path1)
    img_name_list2,label_name_list2=tool.generate_list(img_path2,img_path2)
    
    number=len(img_name_list1)
    name_list=[]
    sum_hard=[]
    sum_mic=[]
    sum_heam=[]
    
    for i in range(number):
        img=image.imread(img_name_list1[i])
        img1=image.imread(img_name_list2[i])

        x,y,z=img.shape
        imgr=tool.imresize(img1)  
        stamp,prob_map=tool.optic_disc_seg(imgr,net_vessel,crop_size=256,stride=128,ctx=ctx1,threshold=0.5)
        stamp=cv2.resize(stamp, (y, x), interpolation=cv2.INTER_NEAREST)
        prob_map=cv2.resize(prob_map.asnumpy(), (y, x), interpolation=cv2.INTER_NEAREST)
        
        hardpr=prob_map_get(img,net_hard,ctx=ctx2,crop_size=256,stride=128,threshold=0.5)
        heampr=prob_map_get(img,net_heam,ctx=ctx4,crop_size=256,stride=128,threshold=0.5)
        micpr=prob_map_get(img,net_mic,ctx=ctx3,crop_size=256,stride=128,threshold=0.5)

        hard_mask=(hardpr.asnumpy()*(1-stamp)*(1-prob_map))>0.5
        mic_mask=((1-stamp)*(1-heampr.asnumpy())*micpr.asnumpy())>0.5
        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(10,10))
        mic_mask = cv2.morphologyEx((mic_mask*np.array([1])).astype('uint8'), cv2.MORPH_OPEN, kernel)
        heam_mask=((1-stamp)*(1-prob_map)*heampr.asnumpy())>0.5
        
        hardpr1=hardpr.asnumpy()*hard_mask
        micpr1=micpr.asnumpy()*mic_mask
        heampr1=heampr.asnumpy()*heam_mask
        
        img_name=img_name_list1[i].split('/')[-1]
        print(img_name)
        name_list.append(img_name)
        sum_hard.append(int(np.sum(hardpr1)))    
        sum_mic.append(int(np.sum(micpr1)))
        sum_heam.append(int(np.sum(heampr1)))
        whole_data.append([img_name,int(np.sum(hardpr1)),int(np.sum(micpr1)),int(np.sum(heampr1))])
        
    return whole_data
        
        
        
        
コード例 #2
0
def load_data(
        batch_size,
        is_reversed=False,
        img_path="/data/dataset/SiZe/hard_e_datasets/train_patch/",
        label_path="/data/dataset/SiZe/hard_e_datasets/train_label_patch/"):
    img_in_list = []
    img_out_list = []

    img_name_list, label_name_list = tools.generate_list(img_path, label_path)
    n = len(img_name_list)

    for i in range(n // 20):
        print(i)
        img_in = image.imread(img_name_list[i]).astype(np.float32) / 127.5 - 1
        label_out = image.imread(label_name_list[i])
        label_out = image2label(label_out)

        img_in = nd.transpose(img_in, (2, 0, 1))
        img_in = img_in.reshape((1, ) + img_in.shape)
        label_out = label_out.reshape((1, ) + label_out.shape)

        img_in_list.append(img_in)
        img_out_list.append(label_out)
    return mx.io.NDArrayIter(
        data=[nd.concat(*img_in_list, dim=0),
              nd.concat(*img_out_list, dim=0)],
        batch_size=batch_size)
コード例 #3
0
def read_images(
        img_path="/data/dataset/SiZe/hard_e_datasets/train_patch/",
        label_path="/data/dataset/SiZe/hard_e_datasets/train_label_patch/"):
    img_name_list, label_name_list = tools.generate_list(img_path, label_path)
    n = len(img_name_list)
    n1 = len(label_path)
    data, label = [None] * (n // 4), [None] * (n // 4)
    for i in range(n // 4):
        print(i)
        data[i] = image.imread(img_name_list[i])
        label[i] = image.imread(label_name_list[i])
    return data, label
コード例 #4
0
def h5_maker(img_path, label_path):
    img_name_list, label_name_list = tools.generate_list(img_path, label_path)
    num1 = len(img_name_list)
    num2 = len(label_name_list)
    if num1 != num2:
        print('data and label is not match')
        return
    img_list = []
    label_list = []

    for i in range(num1):
        img_t = image.imread(img_name_list[i])
        img_t = img_t.transpose((2, 0, 1))
        img_list.append(img_t)
        label_img_t = image.imread(label_name_list[i])
        label_t = image2label(label_img_t)
        label_list.append(label_t)

    with h5py.File("exudates.h5", "w") as f:
        f.create_dataset("img", data=img_list)
        f.create_dataset("label", data=label_list)
コード例 #5
0
classes = ['background', 'target']
colormap = [[0, 0, 0], [255, 255, 255]]
cm2lbl = np.zeros(256**3)
for i, cm in enumerate(colormap):
    cm2lbl[(cm[0] * 256 + cm[1]) * 256 + cm[2]] = i


def image2label(im):
    data = im.astype('int32').asnumpy()
    idx = (data[:, :, 0] * 256 + data[:, :, 1]) * 256 + data[:, :, 2]
    return nd.array(cm2lbl[idx])


img_path = "/data/dataset/SiZe/hard_e_datasets/train_patch/"
label_path = "/data/dataset/SiZe/hard_e_datasets/train_label_patch/"
img_name_list, label_name_list = tools.generate_list(img_path, label_path)


def creat_h5_file(img_name_list, label_name_list):
    for times in range(101):
        print(times)
        if times == 0:
            h5f = h5py.File("train_data.h5", 'w')
            x = h5f.create_dataset("data", (1000, 3, 256, 256),
                                   maxshape=(None, 3, 256, 256),
                                   dtype=np.uint8)
            y = h5f.create_dataset("label", (1000, 256, 256),
                                   maxshape=(None, 256, 256),
                                   dtype=np.float32)
        h5f = h5py.File("train_data.h5", "a")  #add mode
        x = h5f["data"]