Esempio n. 1
0
    def get_Random_train(self, num, path='../nodule_cubes/train_data/csv/'):

        data = []

        for i in tqdm(range(num)):

            while True:
                t = random.randint(0, 299)
                CT = self.traindata[t]
                z = random.randint(30, CT.shape[0]-30)
                y = random.randint(60, CT.shape[1]-60)
                x = random.randint(60, CT.shape[2]-60)
                tmp = CT[z - 16:z + 16, y - 16:y + 16, x - 16:x + 16]

                if (tmp > -600).sum() > 5:
                    break

            v_center = np.array([z, y, x], dtype='float')
            v_center = v_center * self.new_spacings[self.labels[t]] + self.origions[self.labels[t]]

            data.append({'seriesuid': self.labels[t],
                     'coordX': v_center[2],
                     'coordY': v_center[1],
                     'coordZ': v_center[0],
                     'probability': 0.5})

        csv = save_results(path + 'annotations.csv')
        csv.write(data)
Esempio n. 2
0
    def noduleFilter(self):
        New_spacing = np.load(self.pkl_path + 'new_spacing.pkl')
        Origion = np.load(self.pkl_path + 'origion.pkl')
        csvdir = save_results(self.csv_save_path + 'annotations.csv')
        result = []

        for patient in enumerate(tqdm(self.mask_path)):
            patient = patient[1]

            nodules_masks = self.csv_data2[self.csv_data2.file == patient]
            patient_name = nodules_masks.seriesuid.values[0]
            self.mask = np.load(patient)
            origion = Origion[patient_name]
            new_spacing = New_spacing[patient_name]

            for index, nodule in nodules_masks.iterrows():
                nodule_center = np.array([nodule.coordZ, nodule.coordY, nodule.coordX])
                v_center = np.rint((nodule_center - origion) / new_spacing)
                v_center = np.array(v_center, dtype=int)

                if self.mask[v_center[0], v_center[1], v_center[2]] == 0:
                    tmp = {}
                    tmp["seriesuid"] = patient_name
                    tmp["coordX"] = nodule["coordX"]
                    tmp["coordY"] = nodule["coordY"]
                    tmp["coordZ"] = nodule["coordZ"]
                    tmp["probability"] = nodule["probability"]
                    result.append(tmp)

        csvdir.write(result)
        print ('Filter csv: %5d' % (len(result)))
 def save_position(self, path=None):
     if path is None:
         path = './' + self.data_type + '_csv/annotations.csv'
     res = save_results(path)
     res.write(self.position)
     print 'save successfully!'
Esempio n. 4
0
            else:
                negetive_num += 1

    print '[%d / %d]' % (position_num, negetive_num)
    return position


if __name__ == '__main__':
    data = _3D_data(valpath='../nodule_cubes/val_data/')
    labels, valdata, origins, new_spacings, old_spacings = data.get_val()

    model = _3D_CNN_1(weights_path=weights_path)

    index = range(len(valdata))
    # random.shuffle(index)
    # index = index[0:20]

    position = prec(index, [32, 32, 32],
                    labels,
                    origins,
                    new_spacings,
                    stride=[32, 32, 32])
    position = prec(index, [14, 14, 14],
                    labels,
                    origins,
                    new_spacings,
                    stride=[14, 14, 14],
                    position=position)
    reaults = save_results(csvfile_path='./val_csv/annotations.csv')

    reaults.write(position)