예제 #1
0
def get_test_dataset():
    x_return_test = np.zeros((117, size, size, size))
    x_name_test = pd.read_csv("test.csv")['Id']
    filenum = 0
    for i in range(117):
        x_file_temp = os.path.join(x_test_path, x_name_test[i] + '.npz')
        x_voxel = np.array(np.load(x_file_temp)['voxel'])
        x_seg = np.array(np.load(x_file_temp)['seg'])
        x_temp = x_voxel * x_seg * 0.8 + x_voxel * 0.2
        s = x_seg * x_voxel
        sign = np.array(np.nonzero(s))
        min1, low1, len1 = get_rec(sign, 0)
        min2, low2, len2 = get_rec(sign, 1)
        min3, low3, len3 = get_rec(sign, 2)
        i_temp = 0
        for i in range(low1, low1+len1):
            j_temp = 0
            for j in range(low2, low2+len2):
                k_temp = 0
                for k in range(low3, low3+len3):
                    x_return_test[filenum, i, j, k] = x_temp[min1 + i_temp, min2 + j_temp, min3 + k_temp]
                    k_temp += 1
                j_temp += 1
            i_temp += 1
        filenum += 1
    return  x_return_test
예제 #2
0
def load_traindata():
    x_return = np.zeros((495, size, size, size))
    x_name = pd.read_csv("train_val.csv")[
        'Id']  # 此处[' ']内填写的是train_val.csv内的第一列表头
    count_file = 0
    for i in range(len(traindata_list)):
        x_file_temp = os.path.join(traindata_path, x_name[i] + '.npz')
        x_voxel = np.array(np.load(x_file_temp)['voxel'])
        x_mask = np.array(np.load(x_file_temp)['seg'])
        x_temp = x_voxel * x_mask * 0.8 + x_voxel * 0.2

        list_xx = x_mask * x_voxel
        list_xx_nz = np.array(np.nonzero(list_xx))
        coor1min = list_xx_nz[0, :].min()
        coor1max = list_xx_nz[0, :].max()
        coor1len = coor1max - coor1min + 1
        coor1bigger = coor1len - size
        if coor1bigger > 0:
            coor1min += coor1bigger // 2
            coor1max -= coor1bigger - coor1bigger // 2
            coor1len = size
        coor1low = (size // 2) - (coor1len // 2)
        coor1high = coor1low + coor1len
        coor2min = list_xx_nz[1, :].min()
        coor2max = list_xx_nz[1, :].max()
        coor2len = coor2max - coor2min + 1
        coor2bigger = coor2len - size
        if coor2bigger > 0:
            coor2min += coor2bigger // 2
            coor2max -= coor2bigger - coor2bigger // 2
            coor2len = size
        coor2low = (size // 2) - (coor2len // 2)
        coor2high = coor2low + coor2len
        coor3min = list_xx_nz[2, :].min()
        coor3max = list_xx_nz[2, :].max()
        coor3len = coor3max - coor3min + 1
        coor3bigger = coor3len - size
        if coor3bigger > 0:
            coor1min += coor3bigger // 2
            coor3max -= coor3bigger - coor3bigger // 2
            coor3len = size
        coor3low = (size // 2) - (coor3len // 2)
        coor3high = coor3low + coor3len
        coorlist1 = 0
        for coor1 in range(coor1low, coor1high):
            coorlist2 = 0
            for coor2 in range(coor2low, coor2high):
                coorlist3 = 0
                for coor3 in range(coor3low, coor3high):
                    x_return[count_file, coor1, coor2,
                             coor3] = x_temp[coor1min + coorlist1,
                                             coor2min + coorlist2,
                                             coor3min + coorlist3]
                    coorlist3 += 1
                coorlist2 += 1
            coorlist1 += 1
        count_file += 1
    return x_return
예제 #3
0
def load_testdata():
    x_return = np.zeros((117, size, size, size))
    x_name = pd.read_csv("sampleSubmission.csv")[
        'Id']  # 此处[' ']内填写的是sampleSubmission.csv内的第一列表头
    filenum = 0
    for i in range(117):
        x_file_temp = os.path.join(x_test_path, x_name[i] + '.npz')
        x_voxel = np.array(np.load(x_file_temp)['voxel'])
        x_mask = np.array(np.load(x_file_temp)['seg'])
        x_temp = x_voxel * x_mask * 0.8 + x_voxel * 0.2
        list_xx_test = x_voxel * x_mask
        list_xx_nz_test = np.array(np.nonzero(list_xx_test))
        coor1min = list_xx_nz_test[0, :].min()
        coor1max = list_xx_nz_test[0, :].max()
        coor1len = coor1max - coor1min + 1
        coor1bigger = coor1len - size
        if coor1bigger > 0:
            coor1min += coor1bigger // 2
            coor1max -= coor1bigger - coor1bigger // 2
            coor1len = size
        coor1low = (size // 2) - (coor1len // 2)
        coor1high = coor1low + coor1len
        coor2min = list_xx_nz_test[1, :].min()
        coor2max = list_xx_nz_test[1, :].max()
        coor2len = coor2max - coor2min + 1
        coor2bigger = coor2len - size
        if coor2bigger > 0:
            coor2min += coor2bigger // 2
            coor2max -= coor2bigger - coor2bigger // 2
            coor2len = size
        coor2low = (size // 2) - (coor2len // 2)
        coor2high = coor2low + coor2len
        coor3min = list_xx_nz_test[2, :].min()
        coor3max = list_xx_nz_test[2, :].max()
        coor3len = coor3max - coor3min + 1
        coor3bigger = coor3len - size
        if coor3bigger > 0:
            coor1min += coor3bigger // 2
            coor3max -= coor3bigger - coor3bigger // 2
            coor3len = size
        coor3low = (size // 2) - (coor3len // 2)
        coor3high = coor3low + coor3len
        # print(file, coor1low, coor1high, coor2low, coor2high, coor3low, coor3high)
        coorlist1 = 0
        for coor1 in range(coor1low, coor1high):
            coorlist2 = 0
            for coor2 in range(coor2low, coor2high):
                coorlist3 = 0
                for coor3 in range(coor3low, coor3high):
                    x_return[filenum, coor1, coor2,
                             coor3] = x_temp[coor1min + coorlist1,
                                             coor2min + coorlist2,
                                             coor3min + coorlist3]
                    coorlist3 += 1
                coorlist2 += 1
            coorlist1 += 1
        filenum += 1
    return x_return
def fill_below(x, S, Z):
    ind = nx.nonzero(nx.absolute(S-Z)==min(nx.absolute(S-Z)))[0]
    Y = nx.zeros(S.shape)
    Y[:ind] = S[:ind]
    Y[ind:] = Z[ind:]
    p.fill(x, Y, facecolor='blue', alpha=0.5)