Python SimpleITK.sitkUInt8() Examples

The following are 7 code examples of SimpleITK.sitkUInt8(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module SimpleITK , or try the search function .
Example #1
Source File: data_writer.py    From NiftyMIC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def write_mask(
        mask_sitk,
        path_to_file,
        compress=True,
        verbose=True,
        description=None,
    ):
        info = "Write mask to %s" % path_to_file
        if compress:
            mask_sitk = sitk.Cast(mask_sitk, sitk.sitkUInt8)
            info += " (uint8)"
        if verbose:
            ph.print_info("%s ... " % info, newline=False)
        header_update = DataWriter._get_header_update(description=description)

        sitkh.write_nifti_image_sitk(
            mask_sitk, path_to_file, header_update=header_update)
        if verbose:
            print("done") 
Example #2
Source File: getPatchImageAndMask.py    From LiTS---Liver-Tumor-Segmentation-Challenge with MIT License 5 votes vote down vote up
def preparetraindata():
    for i in range(0, 131, 1):
        seg = sitk.ReadImage("D:\Data\LIST\src_data\segmentation-" + str(i) + ".nii", sitk.sitkUInt8)
        segimg = sitk.GetArrayFromImage(seg)
        src = load_itk("D:\Data\LIST\src_data\\volume-" + str(i) + ".nii")
        srcimg = sitk.GetArrayFromImage(src)

        seg_liverimage = segimg.copy()
        seg_liverimage[segimg > 0] = 255

        seg_tumorimage = segimg.copy()
        seg_tumorimage[segimg == 1] = 0
        seg_tumorimage[segimg == 2] = 255
        gen_image_mask(srcimg, seg_liverimage, i, shape=(16, 256, 256), numberxy=5, numberz=10)
	# gen_image_mask(srcimg, seg_tumorimage, i, shape=(16, 256, 256), numberxy=5, numberz=10) 
Example #3
Source File: slice_coverage.py    From NiftyMIC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):

        # create zero image
        coverage_sitk = sitk.Image(self._reconstruction_sitk) * 0

        for i, stack in enumerate(self._stacks):
            print("Slices of stack %d/%d ... " % (i + 1, len(self._stacks)))

            # Add each individual slice contribution
            for slice in stack.get_slices():
                coverage_sitk = self._add_slice_contribution(
                    slice, coverage_sitk)

        # Cast to unsigned integer
        self._coverage_sitk = sitk.Cast(coverage_sitk, sitk.sitkUInt8)

    ##
    # Adds a slice contribution.
    # \date       2019-02-23 21:27:12+0000
    #
    # \param      slice          Slice as sl.Slice object
    # \param      coverage_sitk  sitk.Image reflecting the current iteration of
    #                            slice coverage
    #
    # \return     Updated slice contribution, sitk.Image
    # 
Example #4
Source File: target_stack_estimator.py    From NiftyMIC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _compute_volume(file_path):
        mask_sitk = sitkh.read_nifti_image_sitk(str(file_path), sitk.sitkUInt8)

        # Compute mask volume
        mask_nda = sitk.GetArrayFromImage(mask_sitk)
        spacing = np.array(mask_sitk.GetSpacing())
        volume = np.sum(mask_nda) * spacing.prod()

        return volume 
Example #5
Source File: preprocess.py    From 3DUnetCNN with MIT License 5 votes vote down vote up
def background_to_zero(in_file, background_file, out_file):
    sitk.WriteImage(sitk.Mask(sitk.ReadImage(in_file), sitk.ReadImage(background_file, sitk.sitkUInt8) == 0),
                    out_file)
    return out_file 
Example #6
Source File: preprocess.py    From Keras-Brats-Improved-Unet3d with MIT License 5 votes vote down vote up
def background_to_zero(in_file, background_file, out_file):
    sitk.WriteImage(sitk.Mask(sitk.ReadImage(in_file), sitk.ReadImage(background_file, sitk.sitkUInt8) == 0),
                    out_file)
    return out_file 
Example #7
Source File: brain_stripping.py    From NiftyMIC with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _run_bet_for_brain_stripping(self, debug=0):

        filename_out = "image"

        self._dir_tmp = ph.create_directory(self._dir_tmp, delete_files=True)

        path_to_image = os.path.join(
            self._dir_tmp, filename_out + ".nii.gz")
        path_to_res = os.path.join(
            self._dir_tmp, filename_out + "_bet.nii.gz")
        path_to_res_mask = os.path.join(
            self._dir_tmp, filename_out + "_bet_mask.nii.gz")
        path_to_res_skull = os.path.join(
            self._dir_tmp, filename_out + "_bet_skull.nii.gz")

        sitkh.write_nifti_image_sitk(self._sitk, path_to_image)

        bet = nipype.interfaces.fsl.BET()
        bet.inputs.in_file = path_to_image
        bet.inputs.out_file = path_to_res

        options = ""
        if not self._compute_brain_image:
            options += "-n "

        if self._compute_brain_mask:
            options += "-m "

        if self._compute_skull_image:
            options += "-s "

        options += self._bet_options
        bet.inputs.args = options

        if debug:
            print(bet.cmdline)
        bet.run()

        if self._compute_brain_image:
            self._sitk_brain_image = sitkh.read_nifti_image_sitk(
                path_to_res, sitk.sitkFloat64)

        if self._compute_brain_mask:
            self._sitk_brain_mask = sitkh.read_nifti_image_sitk(
                path_to_res_mask, sitk.sitkUInt8)

        if self._compute_skull_image:
            self._sitk_skull_image = sitkh.read_nifti_image_sitk(
                path_to_res_skull)