Ejemplo n.º 1
0
 def save(self):
     ref = sitk.GetImageFromArray(self.ct_array)
     SaveArrayToNiiByRef(os.path.join(self.case_path, "result_ct.nii.gz"),
                         np.transpose(self.ct_array, (1, 2, 0)), ref)
     SaveArrayToNiiByRef(os.path.join(self.case_path, "result_pet.nii.gz"),
                         np.transpose(self.pet_array, (1, 2, 0)), ref)
     SaveArrayToNiiByRef(os.path.join(self.case_path, "result_cp.nii.gz"),
                         np.transpose(self.cp_array, (1, 2, 0)), ref)
     SaveArrayToNiiByRef(os.path.join(self.case_path, "result_roi.nii.gz"),
                         np.transpose(self.roi_array, (1, 2, 0)), ref)
Ejemplo n.º 2
0
 def get_nii(self):
     reader = sitk.ImageSeriesReader()
     dcm_names = reader.GetGDCMSeriesFileNames(self.dicom_path)
     reader.SetFileNames(dcm_names)
     dcm_image_all = reader.Execute()
     dcm_image_array = sitk.GetArrayFromImage(dcm_image_all)
     dcm_image_array = np.transpose(dcm_image_array, (1, 2, 0))
     try:
         SaveArrayToNiiByRef(store_path=os.path.join(
             self.store_path, "ct.nii"),
                             array=dcm_image_array,
                             ref_image=self.roi)
     except:
         pass
Ejemplo n.º 3
0
    def get_ROI(self, value, store_name):  # value用来选择
        ruangu_roi = os.path.join(self.case_path, "roi.nii.gz")  # 软骨路径
        xiagu_roi = os.path.join(self.case_path,
                                 "moved_new_roi.nii.gz")  # 下骨路径

        data_path = os.path.join(self.case_path, "data_1.nii")
        data_array = standard(np.flipud(get_array_from_path(data_path)))
        data = sitk.ReadImage(data_path)

        ruangu_roi_array = get_array_from_path(ruangu_roi)
        single_ruangu_array = np.where(ruangu_roi_array == value, 1, 0)  # 软骨

        xiagu_roi_array = get_array_from_path(xiagu_roi)
        single_xiagu_array = np.where(xiagu_roi_array == value, 1, 0)  # 下骨

        # 显示检查
        # Imshow3DArray(data_array, [single_ruangu_array, single_xiagu_array])
        SaveArrayToNiiByRef(
            os.path.join(self.case_path, "ruan_gu_" + store_name + ".nii"),
            single_ruangu_array, data)
        SaveArrayToNiiByRef(
            os.path.join(self.case_path, "xia_gu_" + store_name + ".nii"),
            single_xiagu_array, data)
Ejemplo n.º 4
0
 def get_result(self):
     for folder in os.listdir(self.root_path):
         folder_path = os.path.join(self.root_path, folder)
         for case in os.listdir(folder_path):
             case_path = os.path.join(folder_path, case)
             ct_path = os.path.join(case_path, "croped_ct.npy")
             pet_path = os.path.join(case_path, "croped_pet.npy")
             roi_path = os.path.join(case_path, "pred_roi.npy")
             ct_array = np.load(ct_path)
             pet_array = np.load(pet_path)
             roi_array = np.load(roi_path)
             pet_ct_array = pet_array + ct_array
             #############
             #  显示结果
             #############
             roi = sitk.GetImageFromArray(roi_array)
             pet_array = np.transpose(pet_array, (1, 2, 0))
             ct_array = np.transpose(ct_array, (1, 2, 0))
             pet_ct_array = np.transpose(pet_ct_array, (1, 2, 0))
             roi_array = np.transpose(roi_array, (1, 2, 0))
             SaveArrayToNiiByRef(store_path=os.path.join(
                 case_path, "result_ct.nii"),
                                 array=ct_array,
                                 ref_image=roi)
             SaveArrayToNiiByRef(store_path=os.path.join(
                 case_path, "result_pet.nii"),
                                 array=pet_array,
                                 ref_image=roi)
             SaveArrayToNiiByRef(store_path=os.path.join(
                 case_path, "result_ct_pet.nii"),
                                 array=pet_ct_array,
                                 ref_image=roi)
             SaveArrayToNiiByRef(store_path=os.path.join(
                 case_path, "result_roi.nii"),
                                 array=roi_array,
                                 ref_image=roi)
             print("Case {} is finished!".format(case))
Ejemplo n.º 5
0
def flup_pet():
    """将pet的数据进行上下颠倒"""
    root_path = r"Y:\DYB\PETCT_EGFR"
    for folder in os.listdir(root_path):
        folder_path = os.path.join(root_path, folder)
        for case in os.listdir(folder_path):
            case_path = os.path.join(folder_path, case)
            pet_path = os.path.join(case_path, "pet_Resize.nii")
            pet_array = get_array_from_path(pet_path)
            pet_array = np.flipud(pet_array)
            pet = sitk.ReadImage(pet_path)
            SaveArrayToNiiByRef(store_path=os.path.join(case_path, "new_pet_resize.nii"),
                                array=pet_array,
                                ref_image=pet)
            print("case {} is finished!".format(case))
Ejemplo n.º 6
0
def get_new_t2(root_path):
    """对图像进行平滑"""
    for case in os.listdir(root_path):
        t2_path = os.path.join(root_path, case, "T2.nii")
        t2_array = get_array_from_path(t2_path)
        # roi_array = get_array_from_path(os.path.join(root_path, case, "ruan_gu_up_1.nii"))
        new_t2_array = cv2.blur(t2_array, (5, 5))
        new_t2_array = new_t2_array.astype(np.int64)

        t2 = sitk.ReadImage(t2_path)
        SaveArrayToNiiByRef(store_path=os.path.join(root_path, case,
                                                    "new_T2.nii"),
                            array=new_t2_array,
                            ref_image=t2)
        print("Case {} is finished!".format(case))
Ejemplo n.º 7
0
def get_data_roi():
    root_path = r"Y:\DYB\PETCT_EGFR"
    for folder in os.listdir(root_path):
        folder_path = os.path.join(root_path, folder)
        for case in os.listdir(folder_path):
            case_path = os.path.join(folder_path, case)
            ct_path = os.path.join(case_path, "ct.nii")
            roi_path = os.path.join(case_path, "no_name.nii")
            data = sitk.ReadImage(ct_path)
            ct_array = get_array_from_path(ct_path)
            roi_array = get_array_from_path(roi_path)
            roi_array = np.flipud(roi_array)
            SaveArrayToNiiByRef(store_path=os.path.join(
                case_path, "ct_roi.nii"),
                                array=roi_array,
                                ref_image=data)
            print(case)