示例#1
0
    def registraion_to_common_space(self, ref_img, ref_lab, structure=205):
        self.structure = structure
        for i in range(self.mv_imgs.num_data):
            print("processing %d" % (i))
            mv_img = self.mv_imgs.get_file_obj(i)
            mv_lab = self.mv_labels.get_file_obj(i)
            ref_lab = recast_pixel_val(mv_lab, ref_lab)
            ref_img = recast_pixel_val(mv_img, ref_img)

            initial_transform = sitk.CenteredTransformInitializer(
                ref_lab, mv_lab, sitk.Euler3DTransform(),
                sitk.CenteredTransformInitializerFilter.GEOMETRY)
            # mv_label_resampled=mv_lab
            # mv_img_resampled=mv_img
            # uncomment the code below if u wanna preregistration
            mv_label_resampled = sitk.Resample(mv_lab, ref_lab,
                                               initial_transform,
                                               sitk.sitkNearestNeighbor, 0,
                                               mv_lab.GetPixelID())

            initial_transform = sitk.CenteredTransformInitializer(
                ref_img, mv_img, sitk.Euler3DTransform(),
                sitk.CenteredTransformInitializerFilter.GEOMETRY)

            mv_img_resampled = sitk.Resample(mv_img, ref_img,
                                             initial_transform,
                                             sitk.sitkLinear, 0,
                                             mv_img.GetPixelID())

            self.__itksave(mv_img, mv_lab, mv_img_resampled,
                           mv_label_resampled, i)
示例#2
0
    def registration_back_to_individual_space(self):
        for i in range(self.mv_imgs.num_data):
            print("processing %d" % (i))

            mv_img = self.mv_imgs.get_file_obj(i)

            mv_lab = self.mv_labels.get_file_obj(i)
            ref_img = self.ref_img.get_file_obj(i)

            ref_img = recast_pixel_val(mv_img, ref_img)

            initial_transform = sitk.CenteredTransformInitializer(
                ref_img, mv_img, sitk.Euler3DTransform(),
                sitk.CenteredTransformInitializerFilter.GEOMETRY)
            # mv_label_resampled=mv_lab
            # mv_img_resampled=mv_img
            # uncomment the code below if u wanna preregistration
            mv_label_resampled = sitk.Resample(mv_lab, ref_img,
                                               initial_transform,
                                               sitk.sitkNearestNeighbor, 0.0,
                                               mv_lab.GetPixelID())
            mv_img_resampled = sitk.Resample(mv_img, ref_img,
                                             initial_transform,
                                             sitk.sitkLinear, 0.0,
                                             mv_img.GetPixelID())

            self.__itksave(mv_img,
                           mv_lab,
                           mv_img_resampled,
                           mv_label_resampled,
                           i,
                           tag="_reg_back",
                           need_write_image=False)
示例#3
0
def de_rotate(refs, tgts, output_dir):
    for r, t in zip(refs, tgts):
        ref = sitk.ReadImage(r)
        lab = sitk.ReadImage(t)
        ref = recast_pixel_val(lab, ref)
        initial_transform = sitk.CenteredTransformInitializer(
            ref, lab, sitk.Euler3DTransform(),
            sitk.CenteredTransformInitializerFilter.GEOMETRY)

        lab_resampled = sitk.Resample(lab, ref, initial_transform,
                                      sitk.sitkNearestNeighbor, 0,
                                      lab.GetPixelID())

        sitk_write_image(lab_resampled,
                         dir=output_dir,
                         name=os.path.basename(t))
示例#4
0
    def de_rotate(self, structure):
        save_dir = self.target_labels.dir_name + "_deRotate"
        self.structure = structure
        for i in range(self.target_labels.num_data):
            print("processing %d" % (i))
            ref = self.references.get_file_obj(i)
            lab = self.target_labels.get_file_obj(i)
            ref = recast_pixel_val(lab, ref)
            initial_transform = sitk.CenteredTransformInitializer(
                ref, lab, sitk.Euler3DTransform(),
                sitk.CenteredTransformInitializerFilter.GEOMETRY)

            lab_resampled = sitk.Resample(lab, ref, initial_transform,
                                          sitk.sitkNearestNeighbor, 0,
                                          lab.GetPixelID())

            self.__itksave_label(lab_resampled, i, save_dir)
        return save_dir