Ejemplo n.º 1
0
    def read_data(self):
        vector_image_sitk = sitkh.read_sitk_vector_image(self._path_to_image,
                                                         dtype=np.float64)

        if self._path_to_image_mask is not None:
            vector_image_sitk_mask = sitkh.read_sitk_vector_image(
                self._path_to_image_mask,
                dtype=np.uint8,
            )

        N_components = vector_image_sitk.GetNumberOfComponentsPerPixel()

        self._stacks = [None] * N_components

        filename_base = os.path.basename(self._path_to_image).split(".")[0]
        for i in range(N_components):
            image_sitk = sitk.VectorIndexSelectionCast(vector_image_sitk, i)
            if self._path_to_image_mask is not None:
                image_sitk_mask = sitk.VectorIndexSelectionCast(
                    vector_image_sitk_mask, i)
            else:
                image_sitk_mask = None

            if self._slice_thickness is None:
                slice_thickness = image_sitk.GetSpacing()[-1]
            else:
                slice_thickness = self._slice_thickness

            filename = filename_base + "_" + str(i)
            self._stacks[i] = st.Stack.from_sitk_image(
                image_sitk=image_sitk,
                filename=filename,
                image_sitk_mask=image_sitk_mask,
                slice_thickness=float(slice_thickness),
            )

        if self._dir_motion_correction is not None:
            motion_updater = mu.MotionUpdater(
                stacks=self._stacks,
                dir_motion_correction=self._dir_motion_correction,
                volume_motion_only=self._volume_motion_only,
            )
            motion_updater.run()
            self._stacks = motion_updater.get_data()
Ejemplo n.º 2
0
    def read_data(self):

        self._check_input()

        self._stacks = [None] * len(self._file_paths)

        for i, file_path in enumerate(self._file_paths):

            if self._file_paths_masks is None:
                file_path_mask = self._get_path_to_potential_mask(file_path)
            else:
                if i < len(self._file_paths_masks):
                    file_path_mask = self._file_paths_masks[i]
                else:
                    file_path_mask = None

            self._stacks[i] = st.Stack.from_filename(
                file_path,
                file_path_mask,
                slice_thickness=self._stacks_slice_thicknesses[i],
                extract_slices=self._extract_slices,
            )

            # if given image is actually a mask, update the filename so that
            # subsequent MotionUpdater can associate the slice transformation
            # files
            if file_path == file_path_mask:
                filename = self._stacks[i].get_filename()
                filename = re.sub(self._suffix_mask, "", filename)
                self._stacks[i].set_filename(filename)

        if self._dir_motion_correction is not None:
            motion_updater = mu.MotionUpdater(
                stacks=self._stacks,
                dir_motion_correction=self._dir_motion_correction)
            motion_updater.run()
            self._stacks = motion_updater.get_data()